Question: Question 1 0.4 pts The following two programs produce the same output. Which of the following is the benefit of writing code the second way?




Question 1 0.4 pts The following two programs produce the same output. Which of the following is the benefit of writing code the second way? Example 1: favorite = input("What's your favorite type of drink?") print("I say water and you say", favorite) if favorite == "water": print("We said the same thing!") healthy = input ("What do you think is the healthiest type of drink?") print("I say water and you say", healthy) if healthy == "water": print("We said the same thing!") Example 2: def say(drink): print("I say water and you say", drink) if drink = "water": print("We said the same thing!") favorite = input("What's your favorite type of drink?") say(favorite) healthy = input("What do you think is the healthiest type of drink?") say(healthy) The second way allows for user input, which cannot be done using the first way The second way allows code to be reused rather than rewritten The second way creates a function and all programs require a function to be created Question 2 0.4 pt: Which of the following properly defines a function called which takes two numbers as parameters and prints which number is bigger. This function does not return anything. For example: bigger (10,50) \# should print "50 is bigger" bigger (60,13) \# should print "60 is bigger" bigger(78, -3) \# should print "78 is bigger" bigger (9,18) \# should print "-9 is bigger" def bigger (10,50) : if 10>50: print("x is bigger") elif 50>10: print(" y is bigger") def bigger (x,y) : if x>y: print (x, , "is bigger") elif y>x: print (y, is bigger") else: print("Both values are", x) def bigger (x,y) : if x>y: return x, "is bigger" elif y>x: return y, is bigger" else: return "Both values are", x Which of the following is NOT a valid value for ' x ' after this code is executed? import random x= random. randrange (1,10) 1 5 10 Question 4 0.4pts Which of the following statements are true? math and random are the only python modules that exist Modules provide developers with added functions to use in addition to the built-in functions like print() The math module must be imported to be used, but the random module does not need to be imported Which of the following is the result of 20736.0 12 12.0 288
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
