Computer Science Review (Basic Python)

Ace your homework & exams now with Quizwiz!

What is the final result of the expression 4 + 5 * 3?

19

What does the following code print? x = 3.4 y = 1 print int(x) print x + y

3 4.4

What is the final result of the expression 2**3?

8

What is the final result of the expression 7 / 3 + 6?

8

What does the following program print? a = "hi" b = 4 c = a * b print type(c)

<type 'str'>

What is the difference between a binary operator and a unary operator?

A binary operator needs two things, while a unary operator only needs one.

In what order should these statements be executed in order to get input from the user and print out the result? A) response = input("Do you like cheese? ") B) print "You have chosen " + confirm C) print "You responded " + response D) confirm = input("Are you sure? ")

A, C, D, B

What is the output of the following program? Assume the user enters "Florence", then "Fernandez". first_name = input("What is your first name? ") last_name = input("What is your last name? ") whole_name = first_name + last_name print whole_name

FlorenceFernandez

Which of the following statements is true about print statements? I. In order to print a string literal, the string must be enclosed in quotes. II. Each print statement will be printed on its own line. III. Print statements will not let you print strings and numbers in the same statement. IV. Print statements are how you display text on the screen.

I, II, IV

On which line of code will Python error? weight = input("How much do you weigh? ") oz_water = weight / 2 print "You should drink " + str(oz_water) print "ounces of water every day"

Line 2

What kind of data does a float variable contain?

Numbers that can have decimal components

What does the function type tell you?

The type of the variable

Which one of the statements below will cause an error?

ans = "hi" + 9

Choose the option that correctly prints out the variable(s).

language = "Python" print "I'm learning " + language

Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?

num = int(input("Enter a number: "))

Which of the following choices is NOT a Python variable type?

number

Choose the correct declaration of a float variable with the value 3.14.

pi = 3.14

Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value Isabella.

print name + ": " + num

Suppose you have a variable defined a = "4". What is the variable type of a?

str

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?

user_age


Related study sets

Accounting multiple choice chapter 10

View Set

ITN 260 Module 15 Review, ITN 260 Module 13 Review, ITN 260 Module 12 Review, Module 14, Quiz: Module 12 Authentication, Quiz 14, Quiz 11

View Set

Macroeconomics Long-Run Economic Growth Quiz

View Set