Summary

This document contains the answers to computer science quizzes. Questions and answers relating to computer programming topics, such as hardware, input/output, Python programming, object-oriented programming. It is a collection of past quizzes.

Full Transcript

10/10/23, 4:54 PM Quiz: Quiz 1 Quiz 1  This is a preview of the published version of the quiz Started: Oct 10 at 4:54p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can reta...

10/10/23, 4:54 PM Quiz: Quiz 1 Quiz 1  This is a preview of the published version of the quiz Started: Oct 10 at 4:54p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can retake this quiz as many times as you like. The highest score will be kept. Question 1 1 pts Computers are machines that: execute programs. design computer programs. are imprecise and slow. carry out a very narrow range of tasks. Question 2 1 pts ________ is the physical aspect of the computer that can be seen. Hardware Software https://learn.ontariotechu.ca/courses/22929/quizzes/54242/take?preview=1 1/5 10/10/23, 4:54 PM Quiz: Quiz 1 Operating system Application program Question 3 1 pts Which parts of the computer store program code? CPU Secondary storage Monitor Keyboard Question 4 1 pts Which of the following hardware devices is NOT considered an input device? Keyboard Monitor Mouse Microphone Question 5 1 pts Which of the following hardware devices is NOT considered an output device? https://learn.ontariotechu.ca/courses/22929/quizzes/54242/take?preview=1 2/5 10/10/23, 4:54 PM Quiz: Quiz 1 Speaker Monitor Printer Microphone Question 6 1 pts What part of the computer carries out arithmetic operations, such as addition, subtraction, multiplication and division? CPU Network Primary storage Secondary storage Question 7 1 pts High-level programming languages were created to: Allow programmers to describe the solution to a problem one CPU instruction at a time Make programming less error-prone and less tedious Maximize the running time of programs Translate CPU instructions into high-level instructions https://learn.ontariotechu.ca/courses/22929/quizzes/54242/take?preview=1 3/5 10/10/23, 4:54 PM Quiz: Quiz 1 Question 8 1 pts What are two of the most important benefits of the Python language? Advanced mathematical equations and fast programs Ease of use and fast programs Ease of use and portability Fast programs and smaller programs Question 9 1 pts The only language a computer can understand is the Machine Language! True False Question 10 1 pts Machine Language is strings of 0s and 1s. True False Question 11 https://learn.ontariotechu.ca/courses/22929/quizzes/54242/take?preview=1 1 pts 4/5 10/10/23, 4:54 PM Quiz: Quiz 1 Compilation is conversion of each instruction of the high-level language to the equivalent sequence of machine language instructions. True False Question 12 1 pts C and Pascal are typical examples of Procedural Programming Languages. True False Question 13 1 pts Python and Java are typical examples of Object-oriented Programming language. True False Not saved https://learn.ontariotechu.ca/courses/22929/quizzes/54242/take?preview=1 Submit Quiz 5/5 10/10/23, 4:57 PM Quiz: Quiz 2 Quiz 2  This is a preview of the published version of the quiz Started: Oct 10 at 4:57p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can retake this quiz as many times as you like. The highest score will be kept. Question 1 1 pts There are some problems that are not solvable algorithmically. True False Question 2 1 pts Even problems than can be solved algorithmically may not be efficiently solvable. True False Question 3 https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 1 pts 1/6 10/10/23, 4:57 PM Quiz: Quiz 2 Algorithm definition: A sequence of well-defined steps used to solve a problem True False Question 4 1 pts A syntax error is a mistake such as a misspelled keyword, a missing punctuation character, or the incorrect use of an operator. True False Question 5 1 pts What is the difference between an editor and an interpreter? (Select all that applies) An editor allows program files to be entered and modified; an interpreter produces an organized list of files An editor converts program files into an executable program; an interpreter reads and executes program files Question 6 1 pts What reads Python programs and executes the program instructions? https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 2/6 10/10/23, 4:57 PM Quiz: Quiz 2 interpreter editor CPU compiler Question 7 1 pts What extension is used for Python files? .dat .txt .py .Python Question 8 1 pts ____________ are instructions to the computer. (select all that applies) Software Programs Keyboards Hardware Question 9 1 pts Computer can execute the code in ____________. https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 3/6 10/10/23, 4:57 PM Quiz: Quiz 2 high-level language machine language assembly language none of the above Question 10 1 pts ___________ translates high-level language program into machine language program. CPU A compiler The operating system An assembler Question 11 1 pts ____________ is an operating system. Visual Basic Java Python Windows XP C++ Question 12 https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 1 pts 4/6 10/10/23, 4:57 PM Quiz: Quiz 2 _____________ is a program that runs on a computer to manage and control a computer's activities. Python Modem Operating system Interpreter Compiler Question 13 1 pts _______ is an object-oriented programming language. (select all that applies) C# C C++ Python Java Question 14 1 pts ________ is interpreted. Python C++ Pascal C https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 5/6 10/10/23, 4:57 PM Quiz: Quiz 2 Question 15 1 pts A ___________ error does not cause the program to abort, but produces incorrect results. syntax logic runtime Question 16 1 pts In Python, a syntax error is detected by the ________ at _________. compiler/at compile time interpreter/at compile time interpreter/at runtime compiler/at runtime Not saved https://learn.ontariotechu.ca/courses/22929/quizzes/54243/take?preview=1 Submit Quiz 6/6 10/10/23, 5:04 PM Quiz: Quiz 3 Quiz 3  This is a preview of the published version of the quiz Started: Oct 10 at 5:04p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can retake this quiz as many times as you like. The highest score will be kept. Question 1 0.07 pts ____________ are instructions to the computer. Hardware Software Keyboard Programs Question 2 0.07 pts Computer can execute the code in ____________. Machine language none of the above Assembly language high-level language https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 1/8 10/10/23, 5:04 PM Quiz: Quiz 3 Question 3 0.08 pts Which of the following statements is true? 1. Python 3 is a newer version, but it is backward compatible with Python 2. 2. Python 3 is a newer version, but it is not backward compatible with Python 2. 3. A Python 2 program can always run on a Python 3 interpreter. 4. A Python 3 program can always run on a Python 2 interpreter. 4 1 3 2 Question 4 0.08 pts ________ is an object-oriented programming language. 1. Java 2. C++ 3. C 4. C# 5. Python 3,5,1 2,3,4 3,4,5 1,2,4,5 https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 2/8 10/10/23, 5:04 PM Quiz: Quiz 3 Question 5 0.08 pts ________ is interpreted. 1. Python 2. C++ 3. C 4. Ada 5. Pascal 4 5 2 3 1 Question 6 0.08 pts Python syntax is case-sensitive. True False True False Question 7 https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 0.08 pts 3/8 10/10/23, 5:04 PM Quiz: Quiz 3 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") 1. A 2. B 3. C 4. D D C B A Question 8 https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 0.08 pts 4/8 10/10/23, 5:04 PM Quiz: Quiz 3 A Python line comment begins with ________. 1. // 2. /* 3. # 4. $$ 4 3 1 2 Question 9 0.08 pts A Python paragraph comment uses the style ________. 1. // comments // 2. /* comments */ 3. ' ' ' comments ' ' ' 4. /# comments #/ 1 2 4 3 Question 10 https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 0.1 pts 5/8 10/10/23, 5:04 PM Quiz: Quiz 3 A ___________ error does not cause the program to abort, but produces incorrect results. 1. syntax 2. runtime 3. logic 4. None of the above 1 4 2 3 Question 11 0.1 pts In Python, a syntax error is detected by the ________ at _________. 1. compiler/at compile time 2. interpreter/at runtime 3. compiler/at runtime 4. interpreter/at compile time 1 4 3 2 Question 12 https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 0.1 pts 6/8 10/10/23, 5:04 PM Quiz: Quiz 3 1. Which of the following code is correct? A) print("Programming is fun") print("Python") print("Computer Science") B) print("Programming is fun") print("Python") print("Computer Science") C) print("Programming is fun") print("Python") print("Computer Science") D) print("Programming is fun") print("Python") print("Computer Science") C A B https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 7/8 10/10/23, 5:04 PM Quiz: Quiz 3 D Not saved https://learn.ontariotechu.ca/courses/22929/quizzes/54244/take?preview=1 Submit Quiz 8/8 10/10/23, 5:06 PM Quiz: Quiz 4 Quiz 4  This is a preview of the published version of the quiz Started: Oct 10 at 5:06p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can retake this quiz as many times as you like. The highest score will be kept. Question 1 0.02 pts What function do you use to read a string? 1. input("Enter a string") 2. eval(input("Enter a string")) 3. enter("Enter a string") 4. eval(enter("Enter a string")) 2 1 3 4 Question 2 0.03 pts What is the result of eval("1 + 3 * 2") ? 1. "1 + 3 * 2" https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 1/19 10/10/23, 5:06 PM Quiz: Quiz 4 2. 7 3. 8 4. "1 + 6" 1 3 4 2 Question 3 0.02 pts An identifier cannot be a keyword. 1. true 2. false 1 2 Question 4 0.03 pts An identifier can contain digits, but cannot start with a digit. 1. true 2. false 1 2 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 2/19 10/10/23, 5:06 PM Quiz: Quiz 4 Question 5 0.03 pts Which of the following is a valid identifier? 1. $343 2. mile 3. 9X 4. 8+9 5. max_radius 1,4 2,5 3 All of the above Question 6 0.03 pts Which of the following is a valid identifier? 1. import 2. mile1 3. MILE 4. (red) 5. "red" 2,3 4 4,1 1,5 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 3/19 10/10/23, 5:06 PM Quiz: Quiz 4 Question 7 0.03 pts What will be displayed by the following code? x=1 x=2*x+1 print(x) 1. 0 2. 1 3. 2 4. 3 5. 4 1 4 2 3 Question 8 0.03 pts What will be displayed by the following code? x=1 x = x + 2.5 print(x) 1. 1 2. 2 3. 3 4. 3.5 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 4/19 10/10/23, 5:06 PM Quiz: Quiz 4 5. The statements are illegal 3 4 1 2 Question 9 0.05 pts What will be displayed by the following code? x, y = 1, 2 x, y = y, x print(x, y) a) 1 1 b) 2 2 c) 1 2 d) 2 1 a d c b Question 10 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 0.04 pts 5/19 10/10/23, 5:06 PM Quiz: Quiz 4 To following code reads two number. Which of the following is the correct input for the code? x, y = eval(input("Enter two numbers: ")) a) 1 2 b) "1 2" c) 1, 2 d) 1, 2, d c b a Question 11 0.03 pts What is the result of 45 / 4? a) 10 b) 11 c) 11.25 d) 12 d c b a https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 6/19 10/10/23, 5:06 PM Quiz: Quiz 4 Question 12 0.03 pts In the expression 45 / 4, the values on the left and right of the / symbol are called ____. 1. operators 2. operands 3. parameters 4. arguments 4 1 2 3 Question 13 0.03 pts What is the result of 45 // 4? a) 10 b) 11 c) 11.25 d) 12 a d c b https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 7/19 10/10/23, 5:06 PM Quiz: Quiz 4 Question 14 0.03 pts Which of the following expressions will yield 0.5? a) 1 / 2 b) 1.0 / 2 c) 1 // 2 d) 1.0 // 2 e) 1 / 2.0 d c d,e a,b,e Question 15 0.03 pts Which of the following expression results in a value 1? a) 2 % 1 b) 15 % 4 c) 25 % 5 d) 37 % 6 d a b https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 8/19 10/10/23, 5:06 PM Quiz: Quiz 4 c Question 16 0.03 pts 25 % 1 is _____ a) 1 b) 2 c) 3 d) 4 e) 0 e d b a c Question 17 0.03 pts 24 % 5 is _____ a) 1 b) 2 c) 3 d) 4 e) 0 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 9/19 10/10/23, 5:06 PM Quiz: Quiz 4 b a d c e Question 18 0.03 pts 2 ** 3 evaluates to __________. a) 9 b) 8 c) 9.0 d) 8.0 d b a c Question 19 0.03 pts 2 ** 3.0 evaluates to __________. a) 9 b) 8 c) 9.0 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 10/19 10/10/23, 5:06 PM Quiz: Quiz 4 d) 8.0 a d c b Question 20 0.03 pts 2 * 3 ** 2 evaluates to __________. a) 36 b) 18 c) 12 d) 81 b c d a Question 21 0.03 pts What is y displayed in the following code? x=1 y=x=x+1 print("y is", y) https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 11/19 10/10/23, 5:06 PM Quiz: Quiz 4 1. y is 0. 2. y is 1 because x is assigned to y first. 3. y is 2 because x + 1 is assigned to x and then x is assigned to y. 4. The program has a compile error since x is re-declared in the statement int y = x = x + 1. 3 2 4 1 Question 22 0.04 pts What is the result of evaluating 2 + 2 ** 3 / 2? a) 4 b) 6 c) 4.0 d) 6.0 b d a c Question 23 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 0.03 pts 12/19 10/10/23, 5:06 PM Quiz: Quiz 4 What is the value of i printed? j=i=1 i += j + j * 5 print("What is i?", i) a) 0 b) 1 c) 5 d) 6 e) 7 e a c b d Question 24 0.03 pts What is x after the following statements? x=1 x *= x + 1 1. x is 1 2. x is 2 3. x is 3 4. x is 4 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 13/19 10/10/23, 5:06 PM Quiz: Quiz 4 4 2 1 3 Question 25 0.03 pts What is x after the following statements? x=2 y=1 x *= y + 1 1. x is 1. 2. x is 2. 3. x is 3. 4. x is 4. 3 2 1 4 Question 26 0.03 pts To add a value 1 to variable x, you write 1. 1 + x = x 2. x += 1 3. x := 1 4. x = x + 1 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 14/19 10/10/23, 5:06 PM Quiz: Quiz 4 5. x = 1 + x 3 1 1,3 2,4,5 Question 27 0.03 pts Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) 1. (A) and (B) are the same 2. (A) and (C) are the same 3. (B) and (C) are the same 4. (A), (B), and (C) are the same 1 2 4 3 Question 28 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 0.03 pts 15/19 10/10/23, 5:06 PM Quiz: Quiz 4 Suppose x is 1. What is x after x += 2? a) 0 b) 1 c) 2 d) 3 e) 4 c a d b Question 29 0.03 pts Suppose x is 1. What is x after x -= 1? a) 0 b) 1 c) 2 d) -1 e) -2 b d c a https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 16/19 10/10/23, 5:06 PM Quiz: Quiz 4 Question 30 0.03 pts What is x after the following statements? x=1 y=2 x *= y + 1 1. x is 1 2. x is 2 3. x is 3 4. x is 4 1 4 3 2 Question 31 0.03 pts Which of the following functions return 4? 1. int(3.4) 2. int(3.9) 3. round(3.4) 4. round(3.9) 2 https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 17/19 10/10/23, 5:06 PM Quiz: Quiz 4 1 3 4 Question 32 0.03 pts The time.time() returns ________________ . 1. the current time. 2. the current time in milliseconds. 3. the current time in milliseconds since midnight. 4. the current time in milliseconds since midnight, January 1, 1970. 5. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time). 3 2 5 1 4 Question 33 0.02 pts Which of the following functions cause an error? 1. int("034") 2. eval("034") 3. int("3.4") 4. eval("3.4") 1 only https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 18/19 10/10/23, 5:06 PM Quiz: Quiz 4 Both 1 and 4 None Both 2 and 3 4 only Not saved https://learn.ontariotechu.ca/courses/22929/quizzes/54469/take?preview=1 Submit Quiz 19/19 10/10/23, 5:12 PM Quiz: Quiz 5 Quiz 5  This is a preview of the published version of the quiz Started: Oct 10 at 5:11p.m. Quiz Instructions Please be informed that late submission is not accepted; so, you are required to submit before the deadline. Multiple attempts are allowed; so, you can retake this quiz as many times as you like. The highest score will be kept. Question 1 0.05 pts What is max(3, 5, 1, 7, 4)? a) 1 b) 3 c) 5 d) 7 e) 4 d e b a c https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 1/9 10/10/23, 5:12 PM Quiz: Quiz 5 Question 2 0.05 pts What is min(3, 5, 1, 7, 4)? a) 1 b) 3 c) 5 d) 7 e) 4 b e a d c Question 3 0.05 pts What is round(3.52)? a) 3.5 b) 3 c) 5 d) 4 e) 3.0 d a https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 2/9 10/10/23, 5:12 PM Quiz: Quiz 5 c b e Question 4 0.07 pts What is round(6.5)? a) 6 b) 7 c) 5 d) 4 e) 8 b a e c d Question 5 0.07 pts What is round(7.5)? a) 6 https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 3/9 10/10/23, 5:12 PM Quiz: Quiz 5 b) 7 c) 5 d) 4 e) 8 c a e b d Question 6 0.07 pts Is pow(a, b) the same as a ** b? No answer text provided. Yes No Question 7 0.05 pts In Python, a string literal is enclosed in __________. 1. parentheses 2. brackets 3. single-quotes 4. double-quotes 5. braces https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 4/9 10/10/23, 5:12 PM Quiz: Quiz 5 1,2 5 1 3,4 Question 8 0.07 pts Which of the following statement prints smith\exam1\test.txt ? 1. print("smith\exam1\test.txt") 2. print("smith\\exam1\\test.txt") 3. print("smith\"exam1\"test.txt") 4. print("smith"\exam1"\test.txt") 2 1 3 4 Question 9 0.06 pts The expression "Good " + 1 + 2 + 3 evaluates to ________. 1. Good123 2. Good6 3. Good 123 4. Illegal expression 4 https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 5/9 10/10/23, 5:12 PM Quiz: Quiz 5 3 1 2 Question 10 0.06 pts What will be displayed by the following code? print("A", end = ' ') print("B", end = ' ') print("C", end = ' ') print("D", end = ' ') 1. ABCD 2. A, B, C, D 3. A B C D 4. A, B, C, D will be displayed on four lines 2 1 3 4 Question 11 0.06 pts Which of the following statements is correct? 1. s = "Chapter " + 1 https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 6/9 10/10/23, 5:12 PM Quiz: Quiz 5 2. s = "Chapter " + str(1) 3. None of the above. 3 2 1 Question 12 0.06 pts Suppose s is "Welcome", what is s.upper()? 1. welcome 2. WELCOME 3. Welcome 3 2 1 Question 13 0.07 pts Suppose s is "\t\tWelcome\n", what is s.strip()? 1. \t\tWelcome\n 2. \t\twelcome\n 3. \t\tWELCOME\n 4. Welcome https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 7/9 10/10/23, 5:12 PM Quiz: Quiz 5 2 4 1 3 Question 14 0.07 pts The format function returns _______. 1. an int 2. a float 3. a str 4. None 4 2 1 3 Question 15 0.07 pts To format a number x to 3 digits after the decimal point, use _______. 1. format(x, "5.3f") 2. format("5.3f", x) 3. format(x, "5.4f") 4. format("5.3f", x) https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 8/9 10/10/23, 5:12 PM Quiz: Quiz 5 1 2 3 4 Question 16 0.07 pts Suppose x is 345.3546, what is format(x, "10.3f")? (note: b represents a blank space) 1. bb345.355 2. bbb345.355 3. bbbb345.355 4. bbb345.354 5. bbbb345.354 4 5 1 2 3 Not saved https://learn.ontariotechu.ca/courses/22929/quizzes/54470/take?preview=1 Submit Quiz 9/9 Quiz 6 Question 10.08 pts The equal comparison operator is: Group of answer choices • != • = • == • <> Flag question: Question 2 Question 20.08 pts To generate a random integer between 0 and 5, use: Group of answer choices • random.randint(0, 5) • random.randint(1, 5) • random.randint(0, 6) • random.randint(1, 6) Flag question: Question 3 Question 30.08 pts Which of the following code displays the area of a circle if the radius is positive. Group of answer choices • if radius != 0: print(radius * radius * 3.14159) • if radius >= 0: print(radius * radius * 3.14159) • if radius > 0: print(radius * radius * 3.14159) • if radius <= 0: print(radius * radius * 3.14159) Flag question: Question 4 Question 40.08 pts What is the output of the following code? x=0 if x < 4: x=x+1 print("x is", x) Group of answer choices • x is 2 • • • • x is 0 x is 1 x is 3 x is 4 Flag question: Question 5 Question 50.08 pts Suppose isPrime is a boolean variable, which of the following is the correct statement for testing if isPrime is true? (select all that applies) Group of answer choices • if isPrime: • if isPrime == True: • if not isPrime == False: • if not isPrime = False: • if isPrime = True: Flag question: Question 6 Question 60.09 pts Analyze the following code: even = False if even = True: print("It is even!") Group of answer choices • The program has a syntax error in line 1 (even = False) • The program runs, but displays nothing • The program runs and displays It is even! • 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: Flag question: Question 7 Question 70.08 pts Analyze the following code. even = False if even: print("It is even!") Group of answer choices • The code displays nothing. • The code is wrong. You should replace if even: with if even == True: • The code is wrong. You should replace if even: with if even = True: • The code displays It is even! Flag question: Question 8 Question 80.16 pts 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") Group of answer choices • x > 0 and y > 0 • x < 0 and z > 0 • nothing displayed • x < 0 and z < 0 Flag question: Question 9 Question 90.09 pts The following code displays ___________. temperature = 50 if temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right") Group of answer choices • too cold • just right • too hot too cold just right • too hot Flag question: Question 10 Question 100.09 pts Analyze the following code: Code 1: if number % 2 == 0: even = True else: even = False Code 2: even = number % 2 == 0 Group of answer choices • Code 2 has compile errors. • Both Code 1 and Code 2 are correct, but Code 2 is better. • Code 1 has compile errors. • Both Code 1 and Code 2 have compile errors. Flag question: Question 11 Question 110.09 pts 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") Group of answer choices • Income is greater than 4000 • none • Income is greater than 4000 followed by Income is greater than 3000 • Income is greater than 3000 • Income is greater than 3000 followed by Income is greater than 4000 Quiz 7 Question 10.05 pts What is the output of the following code snippet? i = 1 while i < 10 : print(i, end = " ") i = i + 2 if i == 5 : i = 9 Group of answer choices • 135 • 139 • 13579 • 1359 Flag question: Question 2 Question 20.05 pts What is the output of the following code snippet? i = 1 while i != 9 : print(i , end = " ") i = i + 1 if i == 9 : print("End") Group of answer choices • 1 End • 1 End (infinite loop) • 1 2 3 4 5 6 7 8 End • 1 2 3 4 5 6 7 8 End (infinite loop) Flag question: Question 3 Question 30.06 pts What is the output of the following code snippet? i = 1 while i < 20 : print(i , " ") i = i + 2 if i == 15 : i = 19 Group of answer choices • 1 3 5 7 9 11 13 15 17 19 • 1 3 5 7 9 11 13 19 • 1 3 5 7 9 11 13 15 17 • 1 3 5 7 9 11 13 17 19 Flag question: Question 4 Question 40.05 pts What is the output of the following code snippet? i = 1 while i <= 10 : print("Inside the while loop") i = i + 10 Group of answer choices • No output because of compilation error. • "Inside the while loop" will be displayed 10 times. • No output after successful compilation. • "Inside the while loop" will be displayed only once. Flag question: Question 5 Question 50.05 pts There two types of repetition structures in Python: condition-controlled loops and counter-controlled loops. Group of answer choices • True • False Flag question: Question 6 Question 60.05 pts What is the value of i at the end of the following code segment? i = 1 while i < 32 : i = i * 2 Group of answer choices • 16 • 31 • 32 • 64 Flag question: Question 7 Question 70.05 pts The following while loop should continue to run as long as the user does not enter a negative number. What condition should be used to achieve this behavior? x = int(input("Enter an integer: ")) while ____________ : x = int(input("Enter an integer: ")) Group of answer choices • x != 0 • x == 0 • x <= 0 • x >= 0 Flag question: Question 8 Question 80.05 pts What is the output of the following code fragment? i = 1 sum = 0 while i <= 15 : sum = sum + i i = i + 1 print("The value of sum is", sum) Group of answer choices • The value of sum is 0 • The value of sum is 105 • The value of sum is 120 • The value of sum is 136 Flag question: Question 9 Question 90.05 pts What is the output of the code snippet given below? i = 0 while i != 11 : print(i, end=" ") i = i + 3 Group of answer choices • 0 3 6 9 12 • 0 3 6 9 12 15 18 • 013579 • 0 3 6 9 12 ... (infinite loop) Flag question: Question 10 Question 100.06 pts What is the output of the following code fragment? i = 1 sum = 0 while i <= 11 : sum = sum + i i = i + 1 print("The value of sum is", sum) Group of answer choices • The value of sum is 65 • The value of sum is 66 • The value of sum is 55 • The value of sum is 56 Flag question: Question 11 Question 110.06 pts What is the last line of output produced by the code snippet below? i = 0 total = 0 while total < 0 : i = i + 1 total = total - i print(i, total) Group of answer choices • 00 • 11 • No output • 0 -1 Flag question: Question 12 Question 120.05 pts Disadvantages to duplicating code: Group of answer choices • All of the options • May need to be corrected in many places • Time-consuming • Makes program large Flag question: Question 13 Question 130.06 pts What is the output of the code snippet given below? i = 0 while i != 11 : print(" ", i) i = i + 2 Group of answer choices • No output • 02468 • 10 12 14 16 18 ... (infinite loop) • 0 2 4 6 8 ... (infinite loop) Flag question: Question 14 Question 140.05 pts What will be the output of the following code snippet? token = False while token: print("Hello") Group of answer choices • "Hello" will continue to be displayed until the user stops the program. • No output because of compilation error. • No output after successful compilation. • "Hello" will be displayed only once. Flag question: Question 15 Question 150.05 pts Python uses indentation as its method of grouping statements. Group of answer choices • True • False Flag question: Question 16 Question 160.05 pts What is the output of the code snippet given below? i = 0 while i != 9 : print(i, end = " ") i = i + 2 Group of answer choices • No output • 02468 • 10 12 14 16 18 ... (infinite loop) • 0 2 4 6 8 10 12 14 ... (infinite loop) Flag question: Question 17 Question 170.05 pts A while loop becomes an infinite loop if a condition never becomes FALSE. Group of answer choices • True • False Flag question: Question 18 Question 180.06 pts What is the output of the code fragment given below? i = 0 j = 0 while i < 27 : i = i + 2 j = j + 1 print("j =", j) Group of answer choices • j = 27 • j = 12 • j = 13 • j = 14 Flag question: Question 19 Question 190.05 pts while loop: while the condition is true, do something. Group of answer choices • • True False Quiz 8 Question 10.05 pts What are the final values of the variables i , j , and n at the end of this loop? i = 0 j = 12 n = 0 while i != j : i = i + 2 j = j - 2 n = n + 1 Group of answer choices • 2 10 1 • 0 12 0 • 663 • 482 Flag question: Question 2 Question 20.05 pts What will be printed by the statements below? a = 10 while a > 5 : print(a , end = " ") a = a - 2 Group of answer choices • • • • 10 8 10 8 6 4 10 8 6 10 9 8 7 6 5 Flag question: Question 3 Question 30.05 pts The range() function can return a list, a string of characters, or a dictionary. Group of answer choices • True • False Flag question: Question 4 Question 40.05 pts What will be printed by the statements below? val = 1 sum = 0 while val < 5 : sum = sum + val val = val + 1 print(sum) Group of answer choices • 4 • 5 • 10 • 15 Flag question: Question 5 Question 50.05 pts Counter-Controlled loop: iterates a specific number of times. Group of answer choices • True • False Flag question: Question 6 Question 60.05 pts What will be printed by the statements below? val = 1 sum = 0 while val < 5 : sum = 0 sum = sum + val val = val + 1 print(sum) Group of answer choices • 15 • 5 • 4 • 10 Flag question: Question 7 Question 70.05 pts The range function can be used to generate a sequence with numbers in descending order. Group of answer choices • True • False Flag question: Question 8 Question 80.05 pts What will be printed by the statements below? for ctr in range(0, 10) : print(ctr, end = " ") Group of answer choices • 02468 • 0123456789 • 013579 • 0 1 2 3 4 5 6 7 8 9 10 Flag question: Question 9 Question 90.05 pts What will be printed by the statements below? for ctr in range(10, 5, -1) : print(ctr, end = " ") Group of answer choices • 6 7 8 9 10 • 10 9 8 7 6 • 5 6 7 8 9 10 • 10 9 8 7 6 5 Flag question: Question 10 Question 100.05 pts Which of the following loops will print the odd numbers between 0 and 20? Group of answer choices num = 0 while num < 20 : print(num, " ") num = num + 2 num = 1 while num < 20 : num = num + 2 print(num, " ") num = 1 while num < 20 : print(num, " ") num = num + 1 num = 1 while num < 20 : print(num, " ") num = num + 2 Flag question: Question 11 Question 110.05 pts Which of the following loops will print the odd numbers between 0 and 20? Group of answer choices num = 1 while num < 20 : num = num + 2 print(num, " ") num = 1 while num < 20 : value = num * 2 - 1 print(value, " ") num = num + 1 num = 1 while num < 10 : print(num, " ") num = num + 2 num = 1 while num < 11 : value = num * 2 - 1 print(value, " ") num = num + 1 Flag question: Question 12 Question 120.05 pts What does the following code compute? sum = 0 count = 0 value = int(input("enter an while value > 0 : sum = sum + value integer")) count = count + 1 value = int(input("enter next integer")) result = sum * 1.0 / count print(result) Group of answer choices • The second smallest value in the input • The average of all the positive integers in the input • The sum of all the positive integers in the input divided by the number of integers in the input • The average of all the integers in the input Flag question: Question 13 Question 130.05 pts What is the output of the code below? for val in range(0, 4) : print("+", end = "") for num in range(0, print("0", val) : end = "") Group of answer choices • ++++000000 • +000+000+000+000 • ++0+00+000 • +0+00+000+0000 Flag question: Question 14 Question 140.05 pts range characteristics: • • • One argument: used as ending limit. Two arguments: starting value and ending limit Three arguments: the third argument is the step value Group of answer choices • True • False Flag question: Question 15 Question 150.05 pts Consider the following for loop: for i in range(0, 10) : print(i) Which of the following while loops will generate the same output? Group of answer choices i = 1 while i < 10 : print(i) i = i + 1 i = 0 while i < 10 : print(i) i = i + 1 i = 1 while i <= 10 : print(i) i = i + 1 i = 0 while i <= 10 : print(i) i = i + 1 Flag question: Question 16 Question 160.05 pts Consider the following while loop: j = 10 while j >= 5 : print("X") j = j - 1 Which of the following for loops will generate the same output? Group of answer choices for j in range(10, -1, -2) : print("X") for j in range(10, 5, -1) : print("X") for j in range(0, 5) : print("X") for j in range(10, 5) : print("X") Flag question: Question 17 Question 170.05 pts What is the output of this loop? counter = 1 for i in range(1, 100) : counter = counter + 1 print(counter) Group of answer choices • 60 • 10 • 100 • 49 Flag question: Question 18 Question 180.05 pts A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). Group of answer choices • True • False Flag question: Question 19 Question 190.05 pts What does the following code snippet print? fruitName = "banana" for letter in fruitName : print(letter, end = " ") Group of answer choices • Nothing, this is an infinite loop • banana • banana • Nothing, there is a syntax error Flag question: Question 20 Question 200.05 pts The range function simplifies the process of writing a for loop. Group of answer choices • True • False Quiz 9 Question 10.09 pts A ___________________________ is a sequence of instructions with a name. Group of answer choices • parameter • function • argument • variable Flag question: Question 2 Question 20.09 pts Consider a function named calc . It accepts two integer arguments and returns their sum as an integer. Which of the following statements is a correct invocation of the calc function? Group of answer choices • total = calc(2, 3) • total = calc() • • total = calc(2) total = calc("2", "3") Flag question: Question 3 Question 30.09 pts One advantage of designing functions as black boxes is that Group of answer choices • the implementation of the function is open for everyone to see. • the result that is returned from black-box functions is always the same data type. • many programmers can work on the same project without knowing the internal implementation details of functions. • there are fewer parameters. Flag question: Question 4 Question 40.09 pts What is supplied to a function when it is called? Group of answer choices • return values • numbers • arguments • variables Flag question: Question 5 Question 50.09 pts Consider a function named avg , which accepts four numbers and returns their average. Which of the following is a correct call to the function avg ? Group of answer choices • average = avg("2", "3", "4", "5") • average = avg(2, 3.14, 4, 5) • avg(2, 3.14, 3, 5, 6) • avg() Flag question: Question 6 Question 60.09 pts Which of the following statements is true about functions in Python? • • • • Group of answer choices Functions can have multiple arguments and can return multiple return values. Functions can have multiple arguments and can return one return value. Functions can have only one argument and can return only one return value. • Functions can have one argument and can return multiple return values. Flag question: Question 7 Question 70.09 pts What Python statement exits a function and gives the result to the caller? Group of answer choices • send • result • def • return Flag question: Question 8 Question 80.09 pts Given the code snippet below, what is returned by the function call: mystery(5,3) ? def mystery(num1, num2) : result = num1 * num2 return result Group of answer choices • 0 • 15 • 2 • 8 Flag question: Question 9 Question 90.09 pts Given the code snippet below, what is returned by the function call: mystery(mystery(5, 3), mystery(5, 3)) ? def mystery(num1, num2) : result = num1 * num2 return result Group of answer choices • 15 • 30 • Error • 225 Flag question: Question 10 Question 100.1 pts What is wrong with the following code snippet? mystery(10, 2) def mystery(num1, num2) : result = num1 ** num2 return result Group of answer choices • nothing, it will return 20 • the function must be defined before the statement that calls it • nothing, it will return 100 • a variable must be used to store the result of the function call Flag question: Question 11 Question 110.09 pts Consider the following function: def w(x, y) : z = x + y return z What is the function's name? Group of answer choices • z • x • w • y Quiz 10 Question 10.1 pts The following function is supposed to compute the area of a triangle and return the area as the function's result. def triangleArea(base, height) : area = base * height / 2 ____________________ What line of code must be placed in the blank to achieve this goal? Group of answer choices • return triangleArea • print area • return area • print(area) Flag question: Question 2 Question 20.05 pts Which of the following statements correctly defines a function? Group of answer choices • functionName(parameterName1, parameterName2) • functionName(parameterName1, parameterName2) : • def functionName(parameterName1, parameterName2) • def functionName(parameterName1, parameterName2) : Flag question: Question 3 Question 30.1 pts What happens in this code snippet if sideLength = -10 ? def cubeSurfaceArea(sideLength) : if sideLength >= 0 : return 6 * (sideLength * sideLength) # There are six sides to a cube; surface area of each side is sideLength squared Group of answer choices • a special value of None will be returned from the function • the function returns 600 • This function returns nothing • the function returns -600 • an error occurs and aborts the program Flag question: Question 4 Question 40.1 pts What is the purpose of this code snippet? def mystery(n) : if n % 2 == 0 : return True else : return False Group of answer choices • to determine if n is positive or negative • to find the remainder of n divided by 2 • to determine if n is even or odd • to find the value of n divided by 2 Flag question: Question 5 Question 50.1 pts When should a computation be turned into a function? Group of answer choices • when it may be used more than once • when it is only used once • only if it contains complex mathematically equations • when it may not be used Flag question: Question 6 Question 60.1 pts The following program is supposed to display a message indicating if the integer entered by the user is even or odd. What is wrong with the program? num = int(input("Enter an integer: ")) print("The integer is", evenOdd(num)) def evenOdd(n) : if n % 2 == 0 : return "even" return "odd" Group of answer choices • The variable num and the parameter variable n must have the same name. • An else clause must be added to the if statement. • • The function definition must appear before the function is called. The input and print statements must reside in a function named main . Flag question: Question 7 Question 70.05 pts The following function is supposed to return -1 when x is negative, +1 when x is positive, or 0 if x is zero. What, if anything, is wrong with the function? def plusMinusZero(x) : if x == 0 : return 0 elif x <= 0 : return -1 else : return 1 Group of answer choices • Nothing is wrong with the function • A return statement must be added at the end of the function • Both occurrences of elif must be replaced with if • The <= must be replaced with < Flag question: Question 8 Question 80.1 pts What is wrong with the following function for computing the amount of tax due on a purchase? def taxDue(amount, taxRate) : amount = amount * taxRate def main() : . . . total = taxDue(subtotal, TAX_RATE) . . . Group of answer choices • The function must return a value • • • The function must print a value The function must take an additional parameter The amount of tax due is not computed correctly Flag question: Question 9 Question 90.1 pts How many return statements can be included in a function? Group of answer choices • One, two or more • Exactly one • One or two • Zero or more Flag question: Question 10 Question 100.1 pts Consider the following functions: def printIt(x) : print(x) def incrementIt(x) : return x + 1 def decrementIt(x) : return x - 1 def doubleIt(x) : return x * 2 Which of the following function calls is not a reasonable thing to do? Group of answer choices • print(decrementIt(5)) • print(printIt(5)) • print(doubleIt(5)) • print(incrementIt(5)) Flag question: Question 11 Question 110.1 pts Consider the following code segment: def f1(): print("a", end="") return "b" def f2(): print("c", end="") d = f1() print(d, end="") print("e", end="") def f3(): print("f", end="") f2() print("g", end="") f3() What output is generated when it runs? Group of answer choices • fcabeg • fg • fcadeg • fcabdeg • fceg Quiz 11 Question 10.05 pts Python function names follow the same rules as those for naming variables. Group of answer choices • True • False Flag question: Question 2 Question 20.05 pts A function implementation/definition specifies what a function does and causes the function to execute. Group of answer choices • True • False Flag question: Question 3 Question 30.05 pts A local variable can be accessed from anywhere in the program. Group of answer choices • True • False Flag question: Question 4 Question 40.05 pts Different functions can have local variables with the same names. Group of answer choices True False Flag question: Question 5 Question 50.05 pts Python allows you to pass multiple arguments to a function. Group of answer choices • True • False Flag question: Question 6 Question 60.05 pts A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it. Group of answer choices • True • False Flag question: Question 7 Question 70.05 pts Unlike other languages, in Python the number of values a function can return is limited to one. Group of answer choices • True • False Flag question: Question 8 Question 80.05 pts The randrange function returns a randomly selected value from a specific sequence of numbers. Group of answer choices • True • False Flag question: Question 9 Question 90.05 pts The first line in a function definition is known as the function______. Group of answer choices • header • return • block • parameter Flag question: Question 10 Question 100.05 pts Which of the following will assign a random integer in the range of 1 through 50 to the variable number? Group of answer choices number = random.randint (1,150) Flag question: Question 11 Question 110.06 pts What will display after the following code is executed? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main() Group of answer choices • The answer is 25. • The statement will cause a syntax error. • The answer is 100. • The answer is 70. Flag question: Question 12 Question 120.06 pts A __________ variable is created inside a function. Group of answer choices • global • constant • named constant • local Flag question: Question 13 Question 130.06 pts The __________ of a local variable is the function in which that variable is created. Group of answer choices • global reach • scope • space • definition Flag question: Question 14 Question 140.06 pts A __________ variable is accessible to all the functions in a program file. Group of answer choices • local • global • keyword • string Flag question: Question 15 Question 150.06 pts When a function is called by its name during the execution of a program, then it is__________. Group of answer choices • executed • located • exported • defined Flag question: Question 16 Question 160.05 pts What type of function can be used to determine whether a number is even or odd? Group of answer choices • math • even • odd • boolean Flag question: Question 17 Question 170.05 pts A value-returning function is_____________. Group of answer choices • called when you want the function to stop • a function that receives a value when called • a single statement that performs a specific task • a function that will return a value back to the part of the program that called it Flag question: Question 18 Question 180.05 pts Which of the following statements causes the interpreter to load the contents of the random module into memory? Group of answer choices • upload random • import random • load random • download random Flag question: Question 19 Question 190.05 pts What is a group of statements that exists within a program for the purpose of performing a specific task? Group of answer choices • a subtask • a subprocess • a process • a function

Use Quizgecko on...
Browser
Browser