Search Header Logo
Unit 1 Python Test

Unit 1 Python Test

Assessment

Presentation

Computers

7th Grade

Hard

Created by

Danielle Staton

Used 3+ times

FREE Resource

29 Slides • 0 Questions

1

Unit 1 Python Test

by Danielle Staton

2

What command creates text output in Python?

​print()

Explanation:

The print() command creates basic text output in the console.

3

What type conversion should be used for the input below?

​sibs = input("Enter the number of siblings you have: ")

Explanation:

Siblings are counted in whole numbers.

(One can't have 3.3 siblings.)

So it makes sense to use integers.

4

What type conversion should be used for the variable total in line 2 below?

​total = 50 + 50

print("The total is: " + total)

Explanation:

Before concatenating, number values must be typecast to strings.

5

What type conversion should be used for the input below?

temp = input("Enter temperature as a decimal value: ")

Explanation:

Values that have a decimal point are represented by floats.

6

Given the following code, choose the output that would appear in the console.

var1 = "Hello "

var2 = "World"

print(var1 + var2)

Explanation:

The + is used to concatenate, or join, two strings together. Strings are designated with quotation marks, which don't appear in the final output.

7

Given the following code, choose the output that would appear in the console.

1​var = "Hello "

var += "World"

print(var)

Explanation:

The +=, or increment operator, performs a + operation, followed by updating the variable with the new value.

8

Add a float() typecast to the code below to prevent an error.

Explanation:

Only numbers can be used in math calculations. Since input is a string, val must be converted before it can be divided.

media

9

Can words be used in math calculations?

media

10

Highlight the literals in the following code.

(There are 4.)

media

11

Change line 2 of this code so that the user's name is printed after the word Hello (on the same line).

media

12

media

13

What will the console print on the screen?​

media

14

Correct the syntax error in the code below so it prints Hello World.

media
media

Explanation:

The print command must be followed by parentheses ( ) around the value being printed.

15

Correct the syntax error in the code below so it prints Hello World.

media

Explanation:

A string literal must be surrounded by " " symbols. Otherwise, the code will look for a variable with that name.

16

Add a str() typecast to the code below to prevent an error.

media
media

Explanation:

In order to concatenate a number with a string, that number must first be converted with a str() typecast.

17

Add an operator to the code below to prevent an error.

media
media

Explanation:

The assignment operator = is used to store values (such as input) in variables.

18

Why is this NOT a useful quality of error messages?

Explanation:

Error messages occur when something unexpected happens. They give information about where the error occurred and what caused it.

media

19

Why are variables useful?

Explanation:

Variables are useful for many reasons.

Some things, such as using values without knowing what they are, cannot be done without variables.

media

20

Rewrite this line of code to use the increment operator.

Explanation:

+= is the same as performing a + operation, followed by a = operation. It increases the variable on the left by the amount on the right.

media
media

21

What symbol is used for the assignment operator?

Explanation:

= is the assignment operator, used to assign values to variables.

For example, my_int = random.randint(1, 5) puts a random value into the variable my_int.

22

In the code below, highlight the concatenation operator. Do NOT highlight the addition operator.

media

Explanation:

Concatenation is when two strings are joined with the + sign. When + is used to add numbers together, it becomes addition.

23

​What is a literal?

media

24

What is the final value stored in total?

​total = "50" + "50"

Explanation:

When two strings are concatenated, the symbols of the second string are placed at the end of the first string. This is true even if those symbols happen to be numeric.

25

Which of the following is an expression, but not a statement?

Explanation:

Expressions produce values, but unless they are part of a larger statement, that value is immediately thrown away.

media

26

What value is the result of this expression?

Explanation:

The modulus operator (%) gives the remainder after division.

media

27

Explanation:

Lines inside a header comment or lines that start with a # symbol are ignored by the computer. They are used as notes to other coders.

media
media

28

What data type is the result of the following expression?

Explanation:

Division always gives a float, even if you are dividing whole numbers. This is because the result of a division is often a fractional value. (In this case, 3.5)

media

29

Explanation:

Input always returns a string, no matter what symbols the user types

(including numeric symbols).

media

Unit 1 Python Test

by Danielle Staton

Show answer

Auto Play

Slide 1 / 29

SLIDE