wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit 3: Basic Python & Console Interaction

Total questions: 21

Worksheet time: 11mins

Name
Class
Date
1.

What is the final result of the expression 10 + 4 * 5

a)
50
b)
20
c)
30
d)
14
2.

What is the final result of the expression 8 / 3 + 6

a)
7.5
b)
8.6667
c)
10
d)
5.3333
3.

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

a)

print(name + ":" )

print(num)

b)

print(name + " wants " + "num " + "candies")

c)

print(name + ": " + str(num))

d)

print(name + ": " + num)

4.

Which one of the statements below will cause an error?

a)

y = "yes" * 6

b)

y = "yes" + 10

c)

y = "yes" + "yes"

d)

y = ("a"*4)+"b"

5.

What does the following program print?

a)

<class 'str'>

b)

<class 'int'>

c)

<class 'float'>

d)

The program crashes & doesn't print anything.

6.

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

a)

int

b)

float

c)

str

d)

number

7.

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


a)

b)

c)

d)

8.

What kind of data does a float variable contain?

a)

Whole numbers

b)

Words

c)

Numbers that can have decimal components

d)

A float is not a Python variable type

9.

What kind of data does an int variable contain?

a)

Whole numbers

b)

Words

c)

Numbers that can have decimal components

d)

A float is not a Python variable type

10.

What does the following code print?

a)

6.8

8.8

b)

6

8.8

c)

6

8

d)

The code causes an error

11.

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?

a)

num = str(input(“Enter a number: “))

b)

num = number(input(“Enter a number: “))

c)

num = input(“Enter a number: “)

d)

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

12.

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

a)

2

b)

25

c)

32

d)

That is not a valid Python expression

13.

What is the character that in (single) -line Python comments begin with?

a)

#

b)

%

c)

*

d)

"

14.

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

a)

A computer can use binary operators, but it cannot use unary operators.

b)

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

c)

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

d)

Binary operators are used for arithmetic expressions, while unary operators are for strings.


15.

On which line of code will Python error?

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

16.

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)

A, B, C, D

b)

B, C, A, D

c)

A, C, D, B

d)

C, B, A, D

17.

What is the output of the following program? Assume the user enters “Gordon”, then “Sumner”.

a)

Sumner Gordon

b)

Gordon

Sumner

c)

GordonSumner

d)

Gordon Sumner

18.

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 string and number characters in the same statement.
IV. Print statements are how you display text on the screen.

a)

I, IV

b)

II, III

c)

I, II, IV

d)

I, III, IV

19.

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?

a)

first_name

b)

f1r5tn4m3

c)

first!name!

d)

1name

20.

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

a)

float

b)

str

c)

bool

d)

num

21.

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

a)

Euler = "2.71828"

b)

Euler = int(2.71828)

c)

Euler = 2.71828

d)

float Euler = 2.71828