answer the stuff withou using # """ In this lesson we will practice creating…
- User
answer the stuff withou using # """ In this lesson we will practice creating functions/subroutines.
Remember it isn't enough to define a function. You need to call it for it to run in your program.
Mathematical Operators:
- Addition 3 + 2
- Subtraction 5 - 4 / Division 6 / 2
- Multiplication 7 * 9 """ **
""" Exercise 1 """ def add(a, b): print(a + b)
add(3, 5)
""" Exercise 2 """ def subtract(a, b): print(a - b)
subtract(10, 4)
""" Exercise 3
""" #Define and call a function called "divide". It should print the quotient #The second parameter is the divisor
If the second parameter is '0', print out the message
"We can't divide by zero!"
user the '/' symbol for dividing
""" Exercise 4
""" #Define and call a function called "largest_of_two". #it should take two parameters and print the largest number #You will need to use an if statement
""" Exercise 5
""" #Define and call a function called "calculate perimeter". #It should take in 4 parameters and print out the perimeter
""" Exercise 6
""" #Define and call a function called "largest_of_three". #it should take three parameters and print the largest number #You will need to use an if statement
- Assistant
Here are the solutions for the exercises you provided:
Exercise 1
pythondef add(a, b): print(a + b) add(3, 5)Exercise 2
pythondef subtract(a, b): print(a - b) subtract(10, 4)Exercise 3
pythondef divide(a, b): if b == 0: print("We can't divide by zero!") else: print(a / b) divide(10, 2) divide(10, 0)Exercise 4
pythondef largest_of_two(a, b): if a > b: print(a) else: print(b) largest_of_two(5, 10)Exercise 5
python