Search Header Logo
Python Review 2

Python Review 2

Assessment

Presentation

Computers

12th Grade

Practice Problem

Medium

Created by

Catherine L Hulcher

Used 4+ times

FREE Resource

12 Slides • 13 Questions

1

total = input('Enter a number: ')

​-total is a variable name storing a variable type.
-The input() function always reads the user’s input as a string.
-The value in total is a string
-you cannot divide a string by an integer (total/4)
-strings are stored in memory as a sequence of characters
-line 2 is trying to divide a string (total) by 4 (an integer) ERROR
-you have to convert the value in total to an integer

media

2

Multiple Choice

Question image

On which line will this program call an error in the console?

1

Line 1

2

Line 2

3

Line 3

4

Line 4

3

-line 2 is trying to divide a string (total) by 4 (an integer) ERROR
-you have to convert the value in total to an integer

-total = int(input('Enter a number: '))
-the int function will change the value to an integer.
-line 3 will also produce an ERROR.
-python does not allow concatenation of a str and an int
-Line 3: print('One quarter of ' + str(total))

-String concatenation = Use the + character to add a variable to another variable

media

This code will produce 2 runtime errors.

4

Multiple Choice

Question image

How do you fix this code?

1
2
3

5

A. no error. Converts input to integer. Converts integer back to string.

media

Which will produce an error?

B. no error. Converts input to integer. Converts integer back to string.

C. no error. Converts input to integer. Prints an integer (no concatenation).

D. Error. Converts input to integer. Tries to concate an integer (1) with a string.

E. no error. Converts input to integer. Converts integer back to string

6

Multiple Choice

Question image

Which line will produce an error?

1

Line A

2

Line B

3

Line C

4

Line D

5

Line E

7

A. Error. Converts input to integer. Does not convert integer(dozen) back to string.

media

Which of the following code snippets will not produce an error, assuming the user inputs an integer?

B. No Error. Converts input to integer. Converts both dozen and 1 back to string.(Notice parentheses.)

C.Error. Converts input to integer. Adds to integers but does not convert to string for the concatenation

D. Error. Inputs a string. Tries to add a string and integer.

E. Error. Converts input to integer. Converts integer back to string but adds an one

8

Multiple Choice

Question image

Which of the following code snippets will not produce an error, assuming the user inputs an integer?

1
2
3
4

9

In Python, you can use the * operator to multiply not only numbers but also lists and strings. When you multiply a list or a string by an integer, Python repeats the content of that list or string the specified number of times.

media
media

​The type() function returns the type of the specified object.

media
media

10

Multiple Choice

Question image

What will be printed to the screen when the following code snippet is run?

1
2
3

11

1. It must start with a letter or the underscore (_).

​2. It should not start with a number.
3. It should only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ). It should not have any other characters or spaces.
4. The names are case-sensitive (i.e., Pythongeeks and PythonGeeks are treated as different variables).
5. It should not be a keyword.

media

12

Multiple Choice

Which of the following cannot be used as a variable name in a Python program?

1

one_word

2

oneWord

3

1word

4

word1

13

Integer Division in Python 

​In Python, integer division, divides the numbers and returns a float.

7/3 = 2

9/3 = 3

9/6 = 1.5

8/3 =2.66666

15.0/6.0 = 2.5

14

Multiple Choice

Which of the following equations will return the lowest value?

1

print(9/6)

2

print (4 / 2)

3

print (15.0 / 6.0)

4

print (8 / 3)

15

Integer Division in Python 

​In Python, // integer division, also referred to as floor division, involves discarding the remainder and returning the whole number part of the quotient.

7//3 = 2

9//3 = 3

9//6 = 1

8//3 =2

15.0//6.0 = 2.0

16

Multiple Choice

Given the assigned values of x and y, which of the following expressions will produce the smallest value?

x = 25 y = 22

1

x % y

2

x / y

3

x // y

4

x * y

17

The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand. It's used to get the remainder of a division problem.

​Modulo Operator %

18

Multiple Choice

Which of the following code snippets will not print 3.0 to the screen?

1
2
3
4

19

Multiple Choice

What will calculate be set to when the following program is run?

calculate = 24 * 2 + 8 2 - 4

1

24

2

60

3

46

4

26

20

Operators in Python are applied in this order:

  1. Operations in parentheses are resolved first, moving from left to right.

  2. ** is resolved second, moving from left to right

  3. *, /, // and % are resolved third, moving from left to right.

  4. + and - are resolved fourth, moving from left to right.

You might recall the “PEMDAS” acronym for remembering the order of operations in math, and thankfully it still applies here.

21

Multiple Choice

What does the modulus operator return?

1

The rounded quotient when one number is divided by another.

2

The truncated quotient when one number is divided by another.

3

The answer when one number is raised to the power of another.

4

The remainder when one number is divided by another.

22

A. No Error. Converts 5 to string. Y is a string. Prints both strings

Which of the following code snippets will produce an error?

B. No Error. 5 is an integer. 4 is converted to an integer. Thus adds two integers.

C. No Error. Concatenates two strings. Puts 5 and 4 together making 54.

D. No Error. multiplies a string 5 times.

E. Error. Cannot multiply two strings.

media

23

Multiple Choice

Which of the following code snippets will produce an error?

1
2
3
4

24

Method #1: Commenting Using Multiple Single Line #





Method #2: Commenting Using Triple-Quoted String Literals
An alternative method for commenting out multiple lines is to use triple-quoted string literals (' ' ' ' ' ' or " " " " " ").

media
media
media

25

Multiple Choice

Which of the following will result in an error?

1
2
3

total = input('Enter a number: ')

​-total is a variable name storing a variable type.
-The input() function always reads the user’s input as a string.
-The value in total is a string
-you cannot divide a string by an integer (total/4)
-strings are stored in memory as a sequence of characters
-line 2 is trying to divide a string (total) by 4 (an integer) ERROR
-you have to convert the value in total to an integer

media

Show answer

Auto Play

Slide 1 / 25

SLIDE