# SimpleCalc Prequisite: [Tutorial on Functions](https://youtu.be/u-OmVr_fT4s) ## Exercise 1: Grabbing User Input _💡 Tick the checkboxes (or work packages) as you complete each sub task. Breaking down a task into it's steps is the same as solving 90% of the problem._ Write a function called `grab_int` that: - [ ] takes a `message` parameter - [ ] prompts the user for a number - [ ] returns that value as an `int` _(hint: typecasting)_ - [x] Outside of the function, call the function - [x] Print out the value ### Example of what the console interaction would look like _Note: `grab_int` is called with "What is your number?"_ ```bash What is your number? 94 Your number is 94 # Expected result ``` ### Complete the code here ```lang-py def grab_input(message): print (message) user_input = input() return user_input user_input = grab_input('What is your number?') print ('Your number is ' + user_input) ``` Done? Congratulations!! 🙌 Now let's knock off Exercise 2. ## Exercise 2: Adding Two Numbers Let's write a function to add 2 numbers. But this time rather than writing the statements to ask input again we will reuse the `grab_int` function you wrote above. ### Examples of what the console interaction would look like ```bash Number 1? 21 Number 2? 4 Your result is 25 # Expected result ``` ### Complete the code here ```lang-py def grab_input(message): print (message) user_input = input() return user_input number1 = grab_input('What is your first number?') number2 = grab_input('What is your second number?') def add(x,y): return int(x) + int(y) sum = str(add (number1, number2)) print ('Your result is ' + sum) ``` You are awesome 🤩 ## Exercise 3: Calculating Sum Now we do nothing. Seriously. Calculating the sum of two numbers is the same as adding two numbers. All we have to do is write function called `sum` that calls `add`. So basically, calling one function from another function. Don't worry, you got this. ### Examples of what the console interaction would look like ```bash Number 1? 21 Number 2? 4 Your result is 25 # Expected result ``` ### Example of a function calling a function ```lang-py def i_say_balls(): print('balls to you') def say_balls(): i_say_balls() say_balls() # remember to call the function! ``` _Note that I leave two empty lines below the defintion of each of my functions. This is a common practice in Python to keep things easy to read._ ### Write your code here ```lang-py ``` Did that? You can now do anything with functions 🎉 ## Exercise 4: Calculating Average 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py def hotdog(): print ('What is your word?') user_input = input() if user_input == "hot dog" or "hotdog" or "Hot Dog": return True else: return False def yes_no(): if hotdog() == True: return print('Yes') else: return print('No') yes_no() ``` Bored already? Let's take it ☝️ a notch with (in the voice of a host of a wrestling match) COOOONDITIONAAALS!! ## Exercise 5: Add or Average? 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py something = 13 ``` I lied earlier 😉 Now you can really do anything with functions 🚀 ## Exercise 6: What if I want to find the difference? 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py something = 13 ``` Almost there.. You got this ✊ ## Exercise 7: Can I multiply? 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py something = 13 ``` Who's the most badass Python developer in the world??! You 👊 ## Exercise 8: Divide & Conquer 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py something = 13 ``` 🥇 Now let's put it all together ## Exercise 9: SimpleCalc 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 interaction would look like #### Example 1: With hot dog ```bash Is Hot Dog? hot dog Yes # Expected result ``` ### Paste your code here ```lang-py something = 13 ``` 💯 I love you 😘