7. Write a function in Python that would take 3 numbers and add all of them together and return the result. After result is returned, print it to the screen (3 points).
def sum_up(n1,n2,n3): return n1+n2+n3 result = sum_up(1,2,3) print(result)
8. Write a function in Python that would take 5 parameters, combine / concatenate them together and inside the function, print the concatenation into the shell. (3 points)
def word_combine(w1,w2,w3,w4,w5): print(f'{w1} {w2} {w3} {w4} {w5}') word_combine('Hi',"My","name","is", "Siri")
Ask yes or no question program
1. Ask user “Ask yes or no question: ” 2. Pick a random number between 1 to 3. 3. If computer pick 1, print “Yes”. 4. If computer pick 2, print “Maybe”. 5. If computer pick 3, print “No”. 6. Repeat/continuously ask the user until user enter “quit”.When the code is done it should do the following
Ask yes or no question? Is it cloudy outside?Maybe
Ask yes or no question? Is the wall red?
Maybe
Ask yes or no question?I am fat?
Yes
Ask yes or no question?quit
9. Write a function in Python that would do above behavior. Do this in Thonny python editor. After it is done, copy and paste the result below. (7 points)
Answer
while True: print() ayc = input("Enter yes or no question? ") if ayc == "quit": break num = random.randint(1,3) if num == 1: print("Yes") elif num == 2: print("Maybe") elif num == 3: print("no")
Below is a broken python codes
budget1 = 50 * 5 print ('result = '+budget1) abigail = 2 ryan = 3 budget2 = abigail + Ryan print('budget2 ' + budget2) hot_day = int('20') < 15 print (hot_day) if hot_day = True print('It is really hot out there') elif: print('It is cool out there') print('I live in '+ hometown hometown = 'Moscow' def subtract(num1 num2): return num1-num2 print(subtract(10,1)) def starwars(prefix): jedi = ['Luke', 'Obiwan', 'Qui Gon' print(jedi['Luke']) starwars('Jedi Master ')
When Above code is fixed, the program will print out the following in the shell.
budget1 250 budget2 5 False It is cool out there I live in Moscow 9 Jedi Master Luke10. Fix above broken python codes in Python editor (Thonny). After it is fixed, copy the corrected code below (12 points)
Answer
budget1 = 50 * 5 print (f'budget1 {budget1}') abigail = 2 ryan = 3 budget2 = abigail + ryan print(f'budget2 {budget2}') hot_day = int('20') < 15 print (hot_day) if hot_day == True: print('It is really hot out there') else: print('It is cool out there') hometown = 'Moscow' print('I live in '+ hometown) def subtract(num1,num2): return num1-num2 sub = subtract(10,1) print(sub) def starwars(prefix): jedi = ['Luke', 'Obiwan', 'Qui Gon'] print(prefix + jedi[0]) starwars('Jedi Master ')