Spence Midterm

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following is used to show not equals? == != !! =!

!=

What is output? print (12 % 5) 5 1 0 2

2

The two basic categories of variable data types are: Strings and numbers Words and letters Decimals and integers Variables and input

Strings and numbers

The symbol used to create a comment is: % # + =

#

Which of the following numbers might this code generate: random.randint(1,9)? 11 0 1 10

1

Consider the following code: x = 5 x = x * 3 print (x) What is output? 5 75 15 27

15

What is output? Select all that apply. c = 6 while (c > 0): print (c) c = c - 2 0 1 2 3 4 5 6

2 4 6

What is output? x = 8 % 2 if (x > 10): print(1) elif (x > 5): print(2) elif (x > 1): print(3) else: print(4) 4 1 2 3

4

Consider the following code: x = 9 y = -2 z = 2 print (x + y * z) What is output? 14 13 9 5

5

Consider the following code: a = 3 b = 2 print (a ** b) What is output? 9 6 1 8

9

What is output by the following? print(type("95")) <class 'num'> <class 'str'> <class 'wor'> <class 'int'>

<class 'str'>

What best defines an algorithm? A set of precise steps used to perform a task, typically on a computer Using IF and ELSE statements in order to gather input and print outputs Steps used to complete a goal Code that does an action

A set of precise steps used to perform a task, typically on a computer

Which of the following is NOT true about all algorithms? All algorithms stop in a finite amount of time. All algorithms can only do number calculations. All algorithms have clear instructions. All algorithms have an order

All algorithms can only do number calculations.

Why can it be helpful to perform mathematical calculations using programming? Choose the best answer. Because computers can quickly do calculations much larger and complex than humans. Because the values stored in variables cannot change. Because computers are used to store digital data, not analog. Programming is an important skill.

Because computers can quickly do calculations much larger and complex than humans.

What is the correct order for the steps the compiler uses in translating code? Run the commands, Translate commands to machine language, Check for mistakes Translate commands to machine language, Check for mistakes, Run the commands Run the commands, Check for mistakes, Translate commands to machine language Check for mistakes, Translate commands to machine language, Run the commands

Check for mistakes, Translate commands to machine language, Run the commands

Which of the following about computers is NOT true? The memory uses binary numbers. The CPU processes commands. Computing devices are electronic. Computing devices translate digital to analog information in order to process the information.

Computing devices translate digital to analog information in order to process the information.

Which of the following is true about main and secondary memory Secondary memory is lost when the device's power is turned off. Main memory is used for storage. Main memory is short term memory used by the CPU in processing commands, secondary memory is more permanent and used for storage. Main memory is more permanent and used for storage, secondary memory is short term memory is used by the CPU in processing commands.

Main memory is short term memory used by the CPU in processing commands, secondary memory is more permanent and used for storage.

What is input? Storing data in the main memory Putting information into the computer Converting code to machine language Displaying information on the screen

Putting information into the computer

What is one downside of converting analog information to a digital format? Limits the technology available. It takes up too much space in memory. When the power is turned off the information is lost. Some information may be lost when it is converted.

Some information may be lost when it is converted.

The following code is intended to find the average of three numbers entered from the keyboard. What is wrong with the code? print ("Enter 3 numbers: ") n1 = float(input ("Enter a number: ")) n2 = float(input ("Enter a number: ")) n3 = float(input ("Enter a number: ")) print (n1 + n2 + n3 /3) Nothing, it correctly finds the average of the three numbers. The code is missing parentheses around n1 + n2 + n3 in the last line. n1, n2, and n3 should use the str command instead of the float command. Nothing, it correctly finds the sum of the three numbers.

The code is missing parentheses around n1 + n2 + n3 in the last line.

Select all the mistakes (there may be more than one) in the following: if (count = 10): print ("Hello") elseif (count > 100): print ("Good-bye") else print("WAIT!") The else should have a : The = should be == there is no end if elseif should be elif

The else should have a : The = should be == elseif should be elif

Consider the following code: for x (7, 10): print (x) What is wrong with the program? The range function should have three parameters. The first line should be for x = range(7, 10): The first line should be for x in range(7, 10): This program is perfectly fine.

The first line should be for x in range(7, 10):

Consider the following code: x = int(input("Enter a number: ")) print (x) What happens if the user types in A? It prints 65. It prints A. This would cause an error: an integer variable cannot store a string. This would cause an error: int and input cannot be used together in the same line.

This would cause an error: an integer variable cannot store a string.

When should you use an ELIF statement? To count user actions To get user input To repeat sections of code To make a follow-up True/ False decision

To make a follow-up True/ False decision

Three of the following values could be stored as strings. When would you NOT use a string command? To store decimal values. To store values NOT used for calculations. To store a list of colors. To store a word.

To store decimal values.

When do you use an else statement? To end an IF statement. To Input a variable To tell what will happen when an if-statement is false. To handle string values

To tell what will happen when an if-statement is false.

What is output by the following? print("Twinkle, \ttwinkle, \tlittle star") Twinkle,______twinkle,___ little star Twinkle, \ttwinkle, \tlittle star Twinkle, twinkle, little star Twinkle, twinkle, little star

Twinkle, _____twinkle, _____little star. Underscore is supposed to be a tab

What is output by the following? Assume the user enters 5 and 4. x = input("Enter a number: ") y = input("Enter a number: ") print("Values: " + x + y) 9 Values: 9 Values: 54 54

Values: 54 ***Remember values are not set put in as integers so you just put the numbers together and do NOT add them

When do we use numbers instead of strings? To store data like phone numbers and street addresses To hold both words and integers When you need to do calculations To input large amounts of data

When you need to do calculations

When do you use a for loop instead of a while loop? (There may be more than one answer.) You know how many times you want the loop to run. To do number calculations. To repeat code. When there is a defined start and end.

You know how many times you want the loop to run. When there is a defined start and end.

Consider the following code: x = input("What year is it?") print(x) The value stored in x is: a number a comment stored in secondary memory a string

a string

The following code could be rewritten using: if (x > 12): if (x < 34): and none of the others not or

and

Consider the following code: x = "apple" y = x z = "banana" print(x + " " + y + "\n" + z) What is output? apple apple banana apple apple banana apple banana apple apple banana

apple apple banana

Consider the following code: print (min("whom", "carton", "landform", "apron", "deposit", "become")) What is output? become apron carton whom

apron

For a loop to stop, the loop control variable must ______________. change be input from the keyboard be true change inside the loop

change inside the loop

Consider the following code: print("computer" + "science") What is output? computerscience computer science Nothing, there is an error - you cannot add words. computer science

computerscience

Which of the following is NOT a data type in Python? integer float string decimal

decimal

You need to make sure a number the user types in is non-negative. Which of the following functions would you use? input pos fabs int

fabs

Write the code to test if the number in the variable text1 is greater than 15. if (text1 > 15): if (text1 > "15"): if (text1 < "15"): if (text1 >= 15):

if (text1 > 15):

For if statements to work in Python you must ____________. add an else to them make decisions about them use them with input commands indent their code block

indent their code block

What command is used to change a string into a number? dec int str chr

int

Which of the following would be the best variable name to store the value of your English letter grade? LG letter_Grade g 1grade

letter_Grade

Write a program that asks the user for their name and how many times to print it. If I enter Ada and 3 it should print: Ada Ada Ada Which loop correctly does this? name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (c > num): print (name) c = c + 1 name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (c <= num): print (name) c = c + 1 name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (num <= name): print (name) c = c + 1 name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (c <= num): print (name)

name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (c <= num): print (name) c = c + 1 (Second one - B)

Which of the following controls computer memory? - operating system - Python - applications - compiler

operating system

Which line of code outputs the decimal portion of a float stored in the variable x? print (x - int(x)) print (x % 1000) print (x) print (x / 1000)

print (x - int(x))

Which of the following is NOT an input device? - scanner - microphone - printer - mouse

printer

Which of the following are true about algorithms? (You may select more than one) must output a string produce a result can perform logical operations can be done by a computer

produce a result can perform logical operations can be done by a computer

Which of the following will correctly output: I know there's a proverb which that says "To err is human," but a human error is nothing to what a computer can do if it tries. - Agatha Christie quote = "\"To err is human,\"" print("I know there's a proverb which that says \n" + quote + "\nbut") print("a human error is nothing to what a computer") print("can do if it tries.\n\n- Agatha Christie") quote = "\"To err is human,\"" print("I know there's a proverb which that says \t" + quote + "\tbut") print("a human error is nothing to what a computer") print("can do if it tries.\t\t- Agatha Christie") quote = "To err is human," print("I know there's a proverb which that says \n" + quote + "\nbut") print("a human error is nothing to what a computer") print("can do if it tries.\n\n- Agatha Christie") quote = "\"To err is human,\"" print("I know there's a proverb which that says \n + quote + \nbut") print("a human error is nothing to what a computer") print("can do if it tries.\n\n- Agatha Christie")

quote = "\"To err is human,\"" print("I know there's a proverb which that says \n" + quote + "\nbut") print("a human error is nothing to what a computer") print("can do if it tries.\n\n- Agatha Christie") The first one.(A)

To generate integers between and including -10 to 10 you would use: random.randint(-10, 10) randint(-10, 10) random.random(-10, 10) random.random()*20 + -10

random.randint(-10, 10)

You need to find the square root of a value. Which of the following functions would you use? int fabs pow sqrt

sqrt

Which of the following is a legal variable name? 52 1test temperatureAM #data

temperatureAM


संबंधित स्टडी सेट्स

Ch. 7 - Designing Organizational Structures; Ch. 8 - Managing Human Resources and Labor Relations

View Set

Chapter 28: The Civil Rights Movement

View Set

Chapter 9: Courts and Pretrial Processes

View Set

Path: Alterations of hematologic function

View Set

Ohms Law and Electronics Components

View Set

Environmental Mastering Chapter 12

View Set