Source Python COURSE 1-QUIZ 1->5

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of these words are reserved words in Python ? A.if B.machine C.break D.todo E.concat

AC

8.Question 8 What will be the value of x after the following statement executes: X= 1 +2 * 3 - 8 / 4 A.4 B.5.0 C.8 D.2.0

B

.Question 3 Which of the following is a bad Python variable name? A.23spam B._spam C.Spam D.SPAM23

A

10.Question 10 What does the Python input() function do? A.Pause the program and read data from the user B.Connect to the network and retrieve a web page. C.Read the memory of the running program D.Take a screen shot from an area of the screen

A

4. A.What Python statement would you like me to run? B.What is the next machine language instruction to run? C.What Python script would you like me to run? D.What is your favourite color?

A

9.Question 9 What will be the value of x when the following statement is executed: x=int(98.6) A.98 B.6 C.100 D.99

A

In the following Python code, which of the following is an "argument" to a function? x = 'banana' y = max(x) print(y) A/x B/max C/'banana' D/print

A

Question 2 What does the break statement do? A.Exits the currently executing loop B.Exits the program C.Jumps to the "top" of the loop and starts the next iteration D.Resets the iteration variable to its initial value

A

Question 6 What is a good description of the following bit of Python code? zork = 0 for thing in [9, 41, 12, 3, 74, 15] : zork = zork + thing print('After', zork) A/Sum all the elements of a list B/Compute the average of the elements in a list C/Find the smallest item in a list D/Count all of the elements in a list

A

Question 6 What will the following Python code print out? def func(x) : print(x) func(10) func(20) A/10 20 B/x 20 C/def x func func D/x 10 x 20 7.

A

Question 8 What will the following Python program print out? def greet(lang): if lang == 'es': return 'Hola' elif lang == 'fr': return 'Bonjour' else: return 'Hello' print(greet('fr'),'Michael') A/Bonjour Michael B/def Hola Bonjour Hello Michael C/Hola Michael D/Hola Bonjour Hello Michael

A

What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true? A.Indent the line below the if statement B.Underline all of the conditional code C.Start the statement with a "#" character D.Begin the statement with a curly brace {

A

What does the continue statement do? A/Jumps to the "top" of the loop and starts the next iteration B/Resets the iteration variable to its initial value C/Exits the program D/Exits the currently executing loop

A

What does the following Python program print out? tot = 0 for i in [5, 4, 3, 2, 1] : tot = tot + 1 print(tot) A/5 B/15 C/0 D/10

A

What is the iteration variable in the following Python code: friends = ['Joseph', 'Glenn', 'Sally'] for friend in friends : print('Happy New Year:', friend) print('Done!') A/friend B/Glenn C/Sally D/friends

A

What is true about the following code segment: if x == 5 : print('Is 5') print('Is Still 5') print('Third 5') A.Depending on the value of x, either all three of the print statements will execute or none of the statements will execute B.The string 'Is 5' will always print out regardless of the value for x. C.The string 'Is 5' will never print out regardless of the value for x. D.Only two of the three print statements will print out if the value of x is less than zero.

A

What is wrong with this Python loop: n = 5 while n > 0 : print(n) print('All done') A.This loop will run forever B.The print('All done') statement should be indented four spaces C.There should be no colon on the while statement D.while is not a Python reserved word

A

What will the following code print out? smallest_so_far = -1 for the_num in [9, 41, 12, 3, 74, 15] : if the_num < smallest_so_far : smallest_so_far = the_num print(smallest_so_far) Hint: This is a trick question and most would say this code has a bug - so read carefully A/-1 B/74 C/42 D/3

A

What will the following program print out: >>> x = 15 >>> x = x + 5 >>> print(x) A.20 B.5 C.15 D."print x" E.x + 5

A

Which of the following is not a Python reserved word? A.iterate B.continue C.else D.break

A

Which of the following is not one of the programming patterns covered in Chapter 1? A.Random steps B.Conditional Steps C.Sequential Steps D.Repeated Steps

A

Which reserved word indicates the start of an "indefinite" loop in Python? A/while B/indef C/for D/break E/def .

A

For the following code: astr = 'Hello Bob' istr = 0 try: istr = int(astr) except: istr = -1 What will the value be for istr after this code executes? A/false B/-1 C/It will be the 'Not a number' value (i.e. NaN) D/It will be a random number depending on the operating system the program runs on

B

In the following code (numbers added) - which will be the last line to execute successfully? (1) astr = 'Hello Bob' (2) istr = int(astr) (3) print('First', istr) (4) astr = '123' (5) istr = int(astr) (6) print('Second', istr) A/5 B/1 C/2 D/4

B

Question 3 In Python what is the input() feature best described as? 1 point A/A way to retrieve web pages over the network B/A built-in function C/A conditional statement D/The central processing unit

B

What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug - so read carefully). def addtwo(a, b): added = a + b return a x = addtwo(2, 7) print(x) A/addtwo B/2 C/7 D/14

B

What will the following code print out? x = 0 if x < 2 : print('Small') elif x < 10 : print('Medium') else : print('LARGE') print('All done') A/Medium All done B/Small All done C/Small Medium LARGE All done D/Small

B

Which line of the following Python program will never execute? def stuff(): print('Hello') return print('World') stuff() A/def stuff(): B/print ('World') C/print('Hello') D/stuff() E/return

B

Which of these operators is not a comparison / logical operator? A.== B.= C.!= D.>= E.<

B

.Question 9 What is the best way to think about a "Syntax Error" while programming? A.The computer is overheating and just wants you to stop to let it cool down B.The computer has used GPS to find your location and hates everyone from your town C.The computer did not understand the statement that you entered D.The computer needs to have its software upgraded

C

6.Question 6 Which of the following elements of a mathematical expression in Python is evaluated first? A.Subtraction - B.Multiplication * C.Parentheses ( ) D.Addition +

C

7.Question 7 What is "code" in the context of this course? A.A way to encrypt data during World War II B.A set of rules that govern the style of programs C.A sequence of instructions in a programming language D.A password we use to unlock Python features

C

A USB memory stick is an example of which of the following components of computer architecture? A.Main Memory B.Central Processing Unit C.Secondary Memory D.Output Device

C

Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do? x = x +2 A.Increase the speed of the program by a factor of 2 B.Exit the program C.Retrieve the current value for x, add two to it, and put the sum back into x D.This would fail as it is a syntax error

C

In Python, how do you indicate the end of the block of code that makes up the function? A/You put the "END" keyword in column 7 of the line which is to be the last line of the function B/You put a # character at the end of the last line of the function C/You de-indent a line of code to the same indent level as the def keyword D/You add the matching curly brace that was used to start the function }

C

In the following code, print(98.6) What is "98.6"? A.A variable B.A conditional statement C.A constant D.An iteration / loop statement

C

Python scripts (files) have names that end with: A.png B.doc C.py D.exe

C

Question 3 Which of the following variables is the "most mnemonic"? A.x B.variable_173 C.hours D.x1q3z9ocd

C

Question 5 You look at the following text: if x == 6 : print('Is 6') print('Is Still 6') print('Third 6') It looks perfect but Python is giving you an 'Indentation Error' on the second print statement. What is the most likely reason? A/In order to make humans feel inadequate, Python randomly emits 'Indentation Errors' on perfectly good code - after about an hour the error will just go away without any changes to your program B/Python has reached its limit on the largest Python program that can be run C/You have mixed tabs and spaces in the file D/Python thinks 'Still' is a mis-spelled word in the string

C

Question 8 What is a good statement to describe the is operator as used in the following if statement: if smallest is None : smallest = value A/Is true if the smallest variable has a value of -1 B/The if statement is a syntax error C/matches both type and value D/Looks up 'None' in the smallest variable if it is a string

C

What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false? A/A closing curly brace followed by an open curly brace like this }{ B/iterate C/else D/otherwise

C

What is the most important benefit of writing your own functions? A/Following the rule that no function can have more than 10 statements in it B/Following the rule that whenever a program is more than 10 lines you must use a function C/Avoiding writing the same non-trivial code more than once in your program D/To avoid having more than 10 lines of sequential code without an indent or de-indent

C

What is the proper way to say "good-bye" to Python? A,while B.// stop C.quit() D.#EXIT

C

When you have multiple lines in an if block, how do you indicate the end of the if block? A.You use a curly brace { after the last line of the if block B.You omit the semicolon ; on the last line of the if block C.You de-indent the next line past the if block to the same level of indent as the original if statement D.You put the colon : character on a line by itself to indicate we are done with the if block 5.

C

7.Question 7 What is the value of the following expression 42%10 Hint - the "%" is the remainder operator A.0.42 B.10 C.4210 D.2

D

For the following code, if x < 2 : print('Below 2') elif x >= 2 : print('Two or more') else : print('Something else') What value of 'x' will cause 'Something else' to print out? A/x = 2.0 B/x = 22 C/x = -2.0 D/This code will never print 'Something else' regardless of the value for 'x'

D

How many times will the body of the following loop be executed? n = 0 while n > 0 : print('Lather') print('Rinse') print('Dry off!') A/5 B/This is an infinite loop C/1 D/0

D

In the following code x=42 A.A Central Processing Unit B.A constant C.A function D.A variable

D

Question 6 Which of the parts of a computer actually executes the program instructions? A.Secondary Memory B.Main Memory C.Input/Output Devices D.Central Processing Unit

D

What does the following code print out? def thing(): print('Hello') print('There') A/thing B/def thing C/thing Hello There D/There

D

Which Python keyword indicates the start of a function definition? A/return B/sweet C/continue D/def

D


Kaugnay na mga set ng pag-aaral

Lippincott the child with cardiovascular and hematologic health problems, missed questions, childcare

View Set

Prep U Ch. 25 Assessment of Cardiovascular Function, Prep U Ch. 26 Management of Patients With Dysrhythmias and Conduction Problems, MS II Prep U Ch. 26: Management of Patients With Dysrhythmias and Conduction Problems, Prep U Ch. 27 Management of Pa...

View Set

Simplify expressions by combining like terms

View Set

Chapter 8 (Big data) quiz KATHRYN

View Set

Chapter 15, Section 3: The New Deal Affects Many Groups

View Set

Chapter 1 Managers and Management (O)

View Set

Medicinal Chemistry Exam 2 Review

View Set

Sociology Chapter 12 Gender, Sex, and Sexuality

View Set