Python cst101

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

37. Suppose x is 1. What is x after x -= 1? A. 0 B. 1 C. 2 D. -1 E. -2

A. 0

11. Python syntax is case-sensitive. A. True B. False

A. True

39. Which of the following functions cause an error? A. int("034") B. eval("034") C. int("3.4") D. eval("3.4")

B. eval("034") C. int("3.4")

59. The header of a function consists of ____________. A. function name B. function name and parameter list C. parameter list

B. function name and parameter list

24. Which of the following is a valid variable? A. $343 B. mile C. 9X D. 8+9 E. max_radius

B. mile

61. Arguments to functions always appear within __________. A. brackets B. parentheses C. curly braces D. quotation marks

B. parentheses

56. Assume x = 4 and y = 5 Which of the following is true? A. x < 5 and y < 5 B. x < 5 or y < 5 C. x > 5 and y > 5 D. x > 5 or y > 5

B. x < 5 or y < 5

47. What is the output of the following code? x = 0 if x < 4: x = x + 1 print("x is"x) A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

B. x is 1

23. A variable(identifier) cannot be a keyword? A. true B. false

.true

12. Which of the following code is correct? A. print("Programming is fun") print("Python is fun") B. print("Programming is fun") print("Python is fun") C. print("Programming is fun) print("Python is fun") D. print("Programming is fun) print("Python is fun") A. A B. B C. C D. D

B. print("Programming is fun") print("Python is fun")

45. random.randint(0 1) returns ____________. A. 0 B. 1 C. 0 or 1 D. 2

C. 0 or 1

36. Suppose x is 1. What is x after x += 2? A. 0 B. 1 C. 2 D. 3 E. 4

D. 3

5. Python was created by ____________. A. James Gosling B. Bill Gates C. Steve Jobs D. Guido van Rossum E. Google

D. Guido van Rossum

8.________ is interpreted. A. Python B. C++ C. C D. Ada E. Pascal

A. Python

29. What is the result of 45 / 4? A. 10 B. 11 C. 11.25 D. 12

C.11.25

65. A function with no return statement returns ______. A. void B. nothing C. 0 D. None

D. None

54. Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is the best? I: if age < 16: print("Cannot get a driver's license") if age >= 16: print("Can get a driver?s license") II: if age < 16: print("Cannot get a driver's license") else: print("Can get a driver's license") III: if age < 16: print("Cannot get a driver's license") elif age >= 16: print("Can get a driver's license") IV: if age < 16: print("Cannot get a driver's license") elif age == 16: print("Can get a driver's license") elif age > 16: print("Can get a driver's license") A. I B. II C. III D. IV

.B.II: if age < 16: print("Cannot get a driver's license") else: print("Can get a driver's license")

7. ________ is an object-oriented programming language. A. Java B. C++ C. C D. C# E. Python

A. Java B. C++ D. C# E. Python

58. If a function does not return a value by default it returns ___________. A. None B. int C. double D. public E. null

A. None

4. _____________ is a program that runs on a computer to manage and control a computer's activities. A. Operating system B. Python C. Modem D. Interpreter E. Compiler

A. Operating system

64. Which of the following should be defined as a None function? A. Write a function that prints integers from 1 to 100. B. Write a function that returns a random integer from 1 to 100. C. Write a function that checks whether a number is from 1 to 100. D. Write a function that converts an uppercase letter to lowercase.

A. Write a function that prints integers from 1 to 100.

43. The word True is ________. A. a Python keyword B. a Boolean literal C. same as value 1 D. same as value 0

A. a Python keyword B. a Boolean literal

18. What function do you use to read a string? A. input("Enter a string") B. eval(input("Enter a string")) C. enter("Enter a string") D. eval(enter("Enter a string"))

A. input("Enter a string")

Computer can execute the code in ____________. A. machine language B. assembly language C. high-level language D. none of the above

A. machine language

60. A function _________. A. must have at least one parameter B. may have no parameters C. must always have a return statement to return a value D. must always have a return statement to return multiple values

A. must have at least one parameter

57. Which of the following is equivalent to x != y? A. not (x == y) B. x > y and x < y C. x > y or x < y D. x >= y or| x <= y

A. not (x == y)C. x > y or x < y

35. To add number to sumyou write (Note: Python is case-sensitive) A. number += sum B. number = sum + number C. sum = Number + sum D. sum += number E. sum = sum + number,

A. number += sum B. number = sum + number

19. If you enter 1 2 3 in three separate lines, when you run this program, what will be displayed? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. 1.0 B. 2.0 C. 3.0 D. 4.0.

B. 2.0

41. The "less than or equal to" comparison operator is __________. A. < B. <= C. =< D. << E. !=

B. <=

2. _________ translates high-level language program into machine language program. A. An assembler B. A compiler C. CPU D. The operating system

B. A compiler

14. A Python paragraph comment uses the style ________. A. // comments // B. /* comments */ C. ''' comments ''' D. /# comments #/

C. ''' comments '''

42. The equal comparison operator is __________. A. <> B. != C. == D. =

C. ==

20._______ is the code in natural language mixed with some program code. A. Python program B. A Python statement C. Pseudocode D. A flowchart diagram

C. Pseudocode

3. ____________ is an operating system. A. Java B. C++ C. Windows XP D. Visual Basic E. Python

C. Windows XP

15. A ___________ error does not cause the program to abort

but produces incorrect results. A. syntax B. runtime C. logic , C. logic

28. What will be displayed by the following code? x it

y = 1, 2 x, y = y, x print(x, y) A. 1 1 B. 2 2 C. 1 2 D. 2 1, D.2.1

16. In Python

a syntax error is detected by the ________ at _________. A. compiler/at compile time B. interpreter/at runtime C. compiler/at runtime D. interpreter/at compile time,B. interpreter/at runtime

44. To generate a random integer between 0 and 5 use ________________. A. random.randint(0 5) B. random.randint(0 6) C. random.randrange(0 5) D. random.randrange(0 6)

A. random.randint(0, 5)

34. To add a value 1 to variable xwhen you run this program, what will happen? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. The program runs correctly and displays 1.0 B. The program runs correctly and displays 2.0 C. The program runs correctly and displays 3.0 D. The program runs correctly and displays 4.0 E. The program will have a runtime error on the input.,

you write A. 1 + x = x B. x += 1 C. x := 1 D. x = x + 1 E. x = 1 + x, D.x=1+xB.x+=1

32. 25 % 1 is _____ A. 1 B. 2 C. 3 D. 4 E. 0

E.0

52. Suppose income is 4001 what will be displayed by f the following code? if income > 3000: print("Income is greater than 3000") elif income > 4000: print("Income is greater than 4000") A. none B. Income is greater than 3000 C. Income is greater than 3000 followed by Income is greater than 4000 D. Income is greater than 4000 E. Income is greater than 4000 followed by Income is greater than 3000

B. Income is greater than 3000

62. Does the function call in the following function cause syntax errors? import math def main(): math.sin(math.pi) main() A. Yes B. No

B. No

6. Which of the following statements is true? A. Python 3 is a newer versionbut it is backward compatible with Python 2. B. Python 3 is a newer version, but it is not backward compatible with Python 2. C. A Python 2 program can always run on a Python 3 interpreter. D. A Python 3 program can always run on a Python 2 interpreter.

B. Python 3 is a newer version, but it is not backward compatible with Python 2.

49. Analyze the following code. even = False if even: print("It is even!") A. The code displays It is even! B. The code displays nothing. C. The code is wrong. You should replace if even: with if even == True: D. The code is wrong. You should replace if even: with if even = True:

B. The code displays nothing.

48. Analyze the following code: even = False if even = True: print("It is even!") A. The program has a syntax error in line 1 (even = False) B. The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:. C. The program runs but displays nothing. D. The program runs and displays It is even!.

B. The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:.

22. You can place the line continuation symbol __ at the end of a line to tell the interpreter that the statement is continued on the next line. A. / B. \ C. # D. * E. &

B. \

67. When you invoke a function with a parameter the value of the argument is passed to 8.________ is interpreted. the parameter. This is referred to as _________. A. function invocation B. pass by value C. pass by reference D. pass by name

B. pass by value

25. If you enter 1 2 3 in one line when you run this program what will be displayed? number1 number2 number3 = eval(input("Enter three numbers: ")) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. 1.0 B. 2.0 C. 3.0 D. 4.0

B.2.0

46. Which of the following code displays the area of a circle if the radius is positive. A. if radius != 0: print(radius * radius * 3.14159) B. if radius >= 0: print(radius * radius * 3.14159) C. if radius > 0: print(radius * radius * 3.14159) D. if radius <= 0: print(radius * radius * 3.14159)

C. if radius > 0: print(radius * radius * 3.14159),C. if radius > 0: print(radius * radius * 3.14159)

51. The following code displays ___________. temperature = 50 if temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right") A. too hot B. too cold C. just right D. too hot too cold just right

C. just right

9. To start Python from the command promptuse the command ________. A. execute python B. run python C. python or python3 D. go python,

C. python or python3

10. To run python script file named t.pyuse the command ________. A. execute python t.py B. run python t.py C. python t.py or python3 t.py D. go python t.py,

C. python t.py or python3 t.py

55. The __________ function immediately terminates the program. A. sys.terminate() B. sys.halt() C. sys.exit() D. sys.stop()

C. sys.exit()

13. A Python line comment begins with ________. A. // B. /* C. # D. $$

C.#

30. What is the result of 45 // 4? A. 10 B. 11 C. 11.25 D. 12

C.11.25

33. What is y displayed in the following code? x = 1 y = x = x + 1 print("y is" y) A. y is 0. B. y is 1 because x is assigned to y first. C. y is 2 because x + 1 is assigned to x and then x is assigned to y. D. The program has a compile error since x is redeclared in the statement

D. The program has a compile error since x is redeclared in the statement ,C. y is 2 because x + 1 is assigned to x and then x is assigned to y.

63. Each time a function is invoked the system stores parameters and local variables in an area of memory known as _______ which stores elements in last-in first-out fashion. A. a heap B. storage area C. a stack D. an array

D. an array

50. Suppose x = 1 y = -1 and z = 1. What will be displayed by the following statement? if x > 0: if y > 0: print("x > 0 and y > 0") elif z > 0: print("x < 0 and z > 0") A. x > 0 and y > 0 B. x < 0 and z > 0 C. x < 0 and z < 0 D. nothing displayed

D. nothing displayed

66. Consider the following incomplete code: def f(number): # Missing function body print(f(5)) The missing function body should be ________. A. return "number" B. print(number) C. print("number") D. return number

D. return number

38. Which of the following functions return 4. A. int(3.4) B. int(3.9) C. round(3.4) D. round(3.9)

D. round(3.9)

26. What will be displayed by the following code? x = 1 x = 2 * x + 1 print(x) A. 0 B. 1 C. 2 D. 3 E. 4

D.3

27. What will be displayed by the following code? x = 1 x = x + 2.5 print(x) A. 1 B. 2 C. 3 D. 3.5 E. The statements are illegal

D.3.5

17. Which of the following code is correct? I: print("Programming is fun") print("Python") print("Computer Science") II: print("Programming is fun") print("Python") print("Computer Science") III: print("Programming is fun") print("Python") print("Computer Science") IV: print("Programming is fun") print("Python") print("Computer Science") A. I B. II C. III D. IV

D.IV: print("Programming is fun") print("Python") print("Computer Science")

53. Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct? I: if age < 16: print("Cannot get a driver's license") if age >= 16: print("Can get a driver's license") II: if age < 16: print("Cannot get a driver's license") else: print("Can get a driver's license") III: if age < 16: print("Cannot get a driver's license") elif age >= 16: print("Can get a driver's license") IV: if age < 16: print("Cannot get a driver's license") elif age == 16: print("Can get a driver's license") elif age > 16: print("Can get a driver's license") A. I and II B. II and III C. I II and III D. III and IV E. All correct

E. All correct

21. If you enter 1 2 3 in one linewhen you run this program, what will happen? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. The program runs correctly and displays 1.0 B. The program runs correctly and displays 2.0 C. The program runs correctly and displays 3.0 D. The program runs correctly and displays 4.0 E. The program will have a runtime error on the input.,

E. The program will have a runtime error on the input

40. The time.time() returns ________________ . A. the current time. B. the current time in milliseconds. C. the current time in milliseconds since midnight. D. the current time in milliseconds since midnight January 1 1970. E. the current time in milliseconds since midnight January 1 1970 GMT (the Unix time).

E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)


Set pelajaran terkait

Psych Chapter 4 (Multiple Choice)

View Set

NCLEX musculoskeletal and immune

View Set