Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Practice Exam 1 Multiple Choice and fill in the blank 1. Show the printout of the following code: (write the printout next to each print statement if the print statement is executed in the program). If nothing prints then write “nothing prints”. print(2 ** 3) print(34 % 7) print(3 + 4 * 2 > 2 * 9) number = 4 if number % 3 == 0: print(3 * number) print(4 * number) x = 943; print(x // 100) print(x % 100) print(x, "is", "even" if x % 2 == 0 else "odd") y = -1 y += 1 print(y) 2. If you enter 1 2 3 in three separate lines, when you run this program, what will be the output? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) 1 3. What is the printout of the following code? x, y = 1, 2 x, y = y, x print(x, y) 4. What is print(round(3.52))? 5. What function do you use to read a string? A. B. C. D. enter("Enter a string") eval(input("Enter a string")) eval(enter("Enter a string")) input("Enter a string") 6. Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i? A. B. C. D. print(int(i)) print(i) print(chr(i)) print(str(i)) 7. What is the output of the following code? ch = 'F' if ch >= 'A' and ch <= 'Z': print(ch) 8. The "less than or equal to" comparison operator is ________. 9. 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: 2 10. Suppose x = 1, y = -1, and z = 1. What is the printout of 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. B. C. D. no printout. x > 0 and y > 0 x < 0 and z < 0 x < 0 and z > 0 11. Assume x is 0. What is the output of the following statement? if x > 0: print("x is greater than 0") elif x < 0: print("x is less than 0") else: print("x equals 0") A. B. C. D. x is greater than 0 x is less than 0 None x equals 0 12. What is x after evaluating x = 2 if 2 > 3 else 3 13. Analyze the following code: even = 231 % 2 == 0 if even = True: print("It is even!") else: print("It is odd!") A. B. C. D. The The The The program program program program has a runtime error displays "It is odd!" displays "It is even!" has a syntax error on even = True 3 14. 15. 16. 17. 18. 19. 20. 4 21. 22. 23. 24. 25. 26. 5 27. 28. Programs 29. Write a program that prompts the user to enter the three points (x1, y1), (x2, y2), and (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is s = (side1 + side2 + side3)/2 area s(s side1)(s side2)(s side3) Here is a sample run: Note: The length of a side is ( x1 x2)2 ( y1 y 2)2 30. Write a program that prompts the user to enter three integers and displays them in increasing order. 31. The following program should prompt the user to enter two integers and then print a blank line followed by the product of those two integers. For example, here is the output of the program if the user enters 2 and 3: Enter 2 integers: 2, 3 2 * 3 = 6 6 32. Write a multi-way if-elif-else statement that will print out whether an integer, n, is 4th quartile (between 75 and 100, inclusive) 3rd quartile (between 50 and 74, inclusive) 2nd quartile (between 25 and 49, inclusive) 1st quartile (between 0 and 24, inclusive) Out of range (not between 0 and 100, inclusive) For example, if n is 85, your multiway if-elif-else statement should print out 4th quartile If n is 50, the statement should print out 3rd quartile If n is 101, the statement should print out Out of range Use the simplest possible multi-way-elif-else statement with the simplest possible Boolean expressions. You may assume that n is declared and assigned a value somewhere in the program before the multi-way-elif-else statement (i.e., you do not need to declare and assign it a value). 7