wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics-02

Total questions: 21

Worksheet time: 32mins

Name
Class
Date
1.

Name the first variable in this code

(a)  

2.

What key term in python allows the user to answer a question

(a)  

3.

Name the programming error which is a grammatical error

(a)  

4.

If you have a syntax error will the code run?

a)

Yes

b)

No

5.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
6.

What will the output be from the following code?

a = 5

b = 6

print((a > 2) and (b > 6))

a)

True

b)

False

c)

Error

d)

56

7.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
8.
What symbol do you use to make a comment in Python?
a)
@
b)
¬
c)
;
d)
#
9.

"def" keyword is used in python to-

a)

def is a variable

b)


define a new conditional variable

c)

use conditional

d)


define a new function

10.

How do you create a variable with the floating number 2.8?

a)

x=2.8

b)

x=float(2.8)

c)

both are correct

11.

How do you create a variable with the numeric value 5?

a)

Both are correct

b)

x=5

c)

x=int(5)

12.

// means:

a)

two times division

b)

integer division

c)

exact division with floating number

d)

Put a slash

13.

Which of the following pieces of code defines a list of all the numbers from 4 to 12?

a)

range(4,12)

b)

range(4, 13)

c)

range( 3,12)

d)

range(3, 13)

14.

A line of text that Python won't try to run as code

a)

Integer

b)

Comment

c)

Strings

d)

Input

15.

Which of these would work as a piece of code?

a)

if string="Dove"

b)

if string=="Dove"

c)

IF string="Dove":

d)

if string=="Dove":

16.

cakeAmount = input()

print "We have", cakeAmount, " cakes"

The above code is run. You type: Six

Select the correct output.

a)

We have 6 cakes

b)

We have six cakes

c)

Error

17.

x = 5

y = 6

print(x*y)

Select the correct answer(s):

a)

x is a variable

b)

x is a value

c)

print() is a funciton

18.

age = 16

message = "my age is: "

print (message, age)

Select the correct answer(s) below:

a)

the output would read:

my age is 16

b)

age is a variable

c)

16 is assigned to the age variable

19.

Examine the code below. On which line of code will there be an 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 if you weigh " + weight)

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

20.

What is the appropriate symbol(s) used for modulus in Python?

a)

%

b)

#

c)

"""

"""

d)

//

21.

What is the best way to get a number from the user to use in a calculation?

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: “))