# Python Zero To Hero Follow the instructions in the code block. Use this Replit [workspace](https://replit.com/join/qzowhycq-larrydalmeida) to write your code. Copy paste the answer into the code block here in the respective exercise so it's saved. You can use it as reference to solve problems in the future. ## Exercise 13: A Simple Calculator This exercise is a project. It contains multiple sub exercises that when finally put together will have a more powerful functionality. You can do the project here: [SimpleCalc](https://hackmd.io/@rashmi-and-larry/SJPtZ82_u) ## Exercise 12: Is Hot Dog v2.0 Write a function that returns `True` if the person enters **"hot dog"** or **"hotdog"**, or **"Hot Dog"**, otherwise `False`. The output of the program should be `Yes` or `No` depending on whether it's a hot dog. Examples of what the console interactions would look like: Example 1: ```bash Is Hot Dog? hot dog Yes # Expected result ``` Example 2: ```bash Is Hot Dog? hotdog Yes # Expected result ``` Example 3: ```bash Is Hot Dog? Muffin No # Expected result ``` Example 4: ```bash Is Hot Dog? Hot Dog Yes # Expected result ``` ```python ``` ## Exercise 11: Shout back [Tutorial on Functions](https://youtu.be/u-OmVr_fT4s) Write a function called `shout_back` that takes an input and returns the string uppercased. _Hint: you can type `my_string.lower()` to lowercase a string. More about that on [GeeksForGeeks](https://www.geeksforgeeks.org/isupper-islower-lower-upper-python-applications/)._ Example 1: ```bash What you you like us to shout? What? What?!!! # Expected Results ``` ```python print('What would you like us to shout?') word_to_shout = input() print (word_to_shout.upper()) ``` ```python def shout_back(): print('What would you like us to shout?') word_to_shout = input() print (word_to_shout.upper()) ``` ```python print('What would you like us to shout?') word_to_shout = input() thing_that_was_shouted_back = shout_back(word_to_shout) print(thing_that_was_shouted_back) ``` ## Exercise 10: Hello Functions Write a function called `hello_fn` that prints out "Hello Functions!". Example 1: ```bash [RUN] Hello Functions! # Expected result ``` ```python def hello_fn(): print('Hello Functions!') ``` ## Exercise 9: String to Int Write a function call `input_int` that takes a user input converts it into it and returns the value. Use that function to accept a user input, add three to it and print it. Example 1: ```bash Provide a number 3 Your result is: 6 # Expected result ``` ```python ``` --- ## Exercise 8: Increment by Three Complete this program that asks a number from the user and increments it by 3. Example of what the console interaction would look like: ```bash Enter a number 2 # Your number 5 # Expected result ``` ```python # ORIGINAL print('Type your desired number') number=input() print('Your number with an increment of 3 is ' + str(int(number)+3)) ``` ```python # HWM IMPROVE THIS print('Type your desired number') user_number = int(input()) MIN_STEP_SIZE = 3 sum = user_number + MIN_STEP_SIZE print('Your number with an increment of 3 is ' + str(sum)) ``` ## Exercise 7: German Names Complete this program that asks the user for their first and last names, then prints it in the format commonly seen in Germany. Example of what the console interaction would look like: ```bash Enter your first name Marcus Enter your last name Aurelius Aurelius, Markus # Expected result ``` ```python print('Hello') print('What is your first name?') first_name=input() print('What is your last name?') last_name=input() print('It is nice to meet you ' + last_name + ', ' + first_name) ``` ```python # HWM IMPROVE THIS print('Hello') print('What is your first name?') first_name = input() print('What is your last name?') last_name = input() print(f'It is nice to meet you {last_name}, {first_name}') ``` ## Exercise 6: Sum and Average Complete this program that asks the user for three numbers, calculates their sum and average, finally prints both out. Example of what the console interaction would look like: ```bash Enter your first number 20 Enter your second number 40 Enter your third number 60 Sum is 120, Average is 40 # Expected result ``` ```python print('Enter your first number') first_number = input() print('Enter your second number') second_number = input() print('Enter your third number') third_number = input() sum = int(first_number) + int(second_number) + int(third_number) print('The sum of the three numbers is ' + str(int(sum))) average=sum/3 print('The average of the three numbers is ' + str(int(average))) ``` ```python # HWM IMPROVE THIS print('Enter your first number') first_number = float(input()) print('Enter your second number') second_number = float(input()) print('Enter your third number') third_number = float(input()) sum = first_number + second_number + third_number print('The sum of the three numbers is ' + str(sum)) # removed unnecessary type casting average = sum / 3 print('The average of the three numbers is ' + str(average)) ``` ## Exercise 5: Rise of the Repeater Complete this program that accepts a number from a user and a word. It should then print out the word as many times as the number provided by the user. _This one might seem too easy but it's more about learning to read and understand code._ Example of what the console interaction would look like: ```bash What would you like me to repeat? "Bokachoda" And how many times? 3 Bokachoda Bokachoda Bokachoda # Expected result ``` ```python print("What would you like me to repeat?") word = input() print("And how many times?") times = int(input()) # Smart ass count = 0 while count < times: print(word) count = count + 1 ``` ```python # HWM IMPROVE THIS print("What would you like me to repeat?") word = input() print("And how many times?") times = int(input()) # Smart ass count = 0 # intialising count variable while count < times: print(word) count += 1 # same as `count = count + 1` ``` ## Exercise 4: Infinite Looper Write a program to print "Bang!" as many times as the user wishes. Example of what the console interaction would look like: ```bash Give me a number 3 Bang! Bang! Bang! # Expected result ``` ```python print('Give me a number') number = int(input()) count = 0 while count < number: print('Bang!') count = count + 1 ``` ```python # HWM IMPROVE THIS print('Give me a number') user_number = int(input()) count = 0 while count < user_number: print('Bang!') count += 1 ``` ## Exercise 3: Is Hot Dog? Complete this program to print "Yes" if the person enters "hot dog", otherwise "No" Examples of what the console interactions would look like: Example 1: ```bash Is Hot Dog? hot dog Yes # Expected result ``` Example 2: ```bash Is Hot Dog? Muffin No # Expected result ``` ```python word = 'Hot Dog' print('Is Hot Dog?') word = input() if word == 'Hot Dog': print('Yes') else: print('No') ``` ```python # HWM IMPROVE THIS print('Is Hot Dog?') word = input() if word == 'Hot Dog': print('Yes') else: print('No') ``` ## Exercise 2: Is Hot Dog? v1.1 Complete this program to print "Yes" if the person enters **"hot dog"** or **"hotdog"**, otherwise "No" Examples of what the console interactions would look like: Example 1: ```bash Is Hot Dog? hot dog Yes # Expected result ``` Example 2: ```bash Is Hot Dog? hotdog Yes # Expected result ``` Example 3: ```bash Is Hot Dog? Muffin No # Expected result ``` ```python # 1 Define all the patterns of hot dog we want to test HOT_DOG_LOWERCASE_WITHOUT_SPACE = 'hotdog' # DONE HOT_DOG_TITLE_CASE = 'Hot Dog' HOT_DOG_LOWERCASE = 'hot dog' # 2 Grab user input print('Is Hot Dog?') user_input = input() # 3 Compare user input with all the patterns we want to test is_some_variation_of_hot_dog = user_input == HOT_DOG_LOWERCASE_WITHOUT_SPACE or user_input == HOT_DOG_TITLE_CASE or user_input == HOT_DOG_LOWERCASE # 4 Print Yes or No depending on whether it matches if is_some_variation_of_hot_dog: print('Yes') else: print('No') ``` ## Exercise 1: Free Tier Limits Complete this program to print "Welcome Mr. Bond" if the person enters James Bond passcode. Examples of what the console interactions would look like: Example 1: ```bash Passcode please arrogant-piece-of-shit84 Welcome Mr. Bond # Expected result ``` Example 2: ```bash Passcode please pompous-moron ACCESS DENIED mothafuka # Expected result ``` ```python # this is how you define a constant value (value that never changes) # in python it's no different from any other var but using ALL CAPS # tells the reader that the value is fixed and should not be re-assigned BONDS_PASSCODE = "arrogant-piece-of-shit84" LARRYS_PASSCODE = "pompous-moron" print("Passcode please") # complete this code ``` ```python passcode = 'arrogant-piece-of-shit84' print('Passcode please') passcode = input() if passcode == 'arrogant-piece-of-shit84': print('Welcome Mr. Bond') else: print('ACCESS DENIED mothafuka') ```