Computer Unit 7 review
Consider the following subprogram: def mult (a, b = 1, c = 1): print (a * b * c) What is output by: print (mult(3, -10)) A. 0 B. 1 C. -30 D. 30
C. -30
What are the reasons we use subprograms? Select all that apply. a.To simplify code b.To ask for user input c.To help us organize longer programs d.For code that will be reused
To simplify code, to help us organize longer programs, for code that will be reused
We call the central part of the program the ______________ program. a.main b.def c.sub d.return
a. Main
Which of the following is NOT a subprogram? a.random b.print c.input d.randint
a. Random
Which of the following is a legal name for a subprogram? a.calculateIt b.try it c.while d.1method
a. calculateIt
We _________ the code to separate the code in subprograms from the main code. a.Indent b.Put colons in c.Repeat d.Print
a.Indent
Which of the following is NOT a reason we use subprograms? a. For code that will be reused b. To test for true and false relationships c. To simplify code d. To help us organize longer programs
b. To test for true and false relationships
Consider the following code: def tryIt (an): val = an * 2 c = 0 if (val < 0): c = 1 return c Which variable is the parameter? a.if b. an c. val d. c
b. an (The "an" is the only variable that passes through the function as it's being defined.)
Consider the following code: def calc(num1, num2 = 0): return(num1 + num2) val1 = int(input(" ")) val2 = int(input(" ")) print(calc(val1)) What is output when the user enters 19 and 18? a.0 b. 18 c. 19 d. 37
c. 19
Consider the following code: def mystery (a, b = 8, c = -6): return a + b + c x = int(input("First value: ")) y = int(input("Second value: ")) z = int(input("Third value: ")) print(mystery (x, y, z)) What is output when the user enters 30, 2 and 2? a.26 b. 32 c. 34 d. 36
c. 34
Consider the following program: def sample(val): val = val - 8 n = 38 sample(n) print(n) What is output? a.8 b.30 c.38 d.n
c. 38
What is output by the following code? def mult(a, b = 2, c = 1): return (a * b * c) print(mult(3)) a.0 b.2 c.6 d.None of the above.
c. 6
Subprograms go _______ the main program. a.within b.below c.above
c. Above
Consider the following code: def volume(x, y, z): return x * y * z v = 0 length = int(input("Length: ")) width = int(input("Width: ")) height = int(input("Height: ")) v = volume(length, width, height) print("Volume:" + str(v)) What is the output if the user enters 3, 7, 2? a.0 b. 42 c. Volume: 42. d. none of the above.
c. Volume: 42
Which of the following parameters is optional? sample(a, b) a. a b. b c. a and b d. None of the parameters are optional.
d. None of the parameters are optional.
Consider the following code: def addIt (a, b): return a + b print (a) What is wrong? a.There should be a third parameter. b.The method cannot return a value. c.The method should only have one parameter. d.The print statement cannot be reached.
d. The print statement cannot be reached.
The __________ keyword is used to return a value from a function. a.Send b.def c.go d.return
d. return
A(n) ____________ variable exists only inside a method and cannot be accessed in main. a.Initializing b.Range c.User input d.Local
d.Local
What is output by the following program? def greeting(name = "?") return "Hello " + name + "!" print(greeting("Joe")) a.Hello Joe! b.Hello c.Hello! d.None of the above.
d.None of the above. (The def function is missing the colon at the end of the code.)
Which of the following parameters is optional? Sample(a,b,c,d=121) A. a B. b C. c D. d
D. d