Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

cs 121 The following two programs produce the same output. Which of the following is the benefit of writing code the second way? Example 1:

cs 121
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 heal thy = "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) heal thy - input ("What do you think is the healthiest type of drink?") say(heol thy) 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 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)bigger60,13)bigger(78,-3)bigger(9,18)#shouldprint"50isbigger"#shouldprint"60isbigger"#shouldprint"78isbigger"#shouldprint"-9isbigger" 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 >>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 : is bigger" return y, is bet 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.4 pts 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 0 The math module must be imported to be used, but the random module does not need to be imported 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 print0 The math module must be imported to be used, but the random module does not need to be imported Question 5 0.4 pts 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

8. Design office space to facilitate interaction between employees.

Answered: 1 week ago