Intro to Programming - Python Review with complete verified solutions 2025

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/42

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

43 Terms

1
New cards

print()

The ______ statement is a command built in to Python. When you run the

.py file, the Python interpreter knows to display whatever is contained

between the ().

2
New cards

b = 6

print(b)

Print the value of a variable "b" that equals 6.

3
New cards

integer

A variable type that holds whole numbers

4
New cards

float

A variable type containing a decimal point

5
New cards

string

The value of this variable type doesn't necessary need to be a letter. We can also

have ______s that are numbers.

6
New cards

print(c)

Use this statement to check the value of a variable "c"

7
New cards

boolean

A Python variable which can only have two

values, True or False. These True of False values reduce down to a 1 or

0, on or off.

8
New cards

myBool = True

print(myBool)

Create a boolean variable that is set to true (case sensitive)

9
New cards

list

''A variable type which can store multiple items together as one variable, and each of those items can actually have

different types.

For example, the first item

could be integer, second item a float, and third item a string.

myList = [4, 6.5, 'a']

print(myList)

'''

myList has three items in and to access each individual item, we use

the index of the item. Indexing starts at 0, so the first item is

myList[0], the second is myList[1], and the third is myList[2]

'''

print(myList[0])

print(myList[1])

print(myList[2])

10
New cards

myList = [4, 6.5, 'a']

print(myList)

Print the list "myList," with values of 4, 6.5, and 'a' respectively.

11
New cards

print(myList[0])

Index the first item in the list "myList"

12
New cards

cast

There are times when you will want to take a variable that is one type and make it behave like it's a different type. We call this ______ing. For

example, if you have a string and you want to be a number, you would ______ it as a float.

13
New cards

x = float(x)

print(x)

Cast the string "x" as a float (take the value at the x location, convert it to a float,

and return it back to the x location.)

14
New cards

x = int(x)

print(x)

Convert the existing value of x to an integer x. If x has a decimal, it will be truncated, and you

will be left with the whole number portion only.

15
New cards

division

Name the operation.

a = 5

b = 6

c = a / b

(Note: c is a floating point number)

16
New cards

multiplication

Name that operation.

z = a*b

print(z)

17
New cards

exponentation

z = a**2

print(z)

18
New cards

addition, multiplication, division

z2 = a + (b * z) / a

print(z2)

19
New cards

radius = 10

area = 3.14 radius*2

circ = 2 3.14 radius

print("the area is:",area)

print("the circumference is:",circ)

Given a circle with a radius of 10 units. Calculate the area and circumference ("circ") of the circle.

The formula for area is a = pi*r^2

The formula for circumference is 2pir

20
New cards

seconds = 200

mins = int(seconds / 60)

s = seconds % 60

print("200 seconds is ",mins, " mins and ", s, "seconds")

Print 200 seconds as a mixed expression of minutes and seconds.

21
New cards

modulus (%)

To convert decimals to mixed expressions, use the ______. (i.e., to convert 200 seconds into minutes and seconds, use the ______ of dividing by 60.)

22
New cards

if mpg < 15:

print("uber polluter")

elif mpg > 30:

print("nice job")

else:

print("not bad")

#if mpg < 15, print uber polluter

#if mpg > 30, print nice job

#if mpg between 15 and 30, print not bad

23
New cards

<

less than

24
New cards

>

greater than

25
New cards

<=

less than or equal to

26
New cards

>=

greater than or equal to

27
New cards

==

equal to

28
New cards

!=

not equal

29
New cards

if a == 3:

print("a equals 3")

Relational operators all perform the same task of specifying a relation in an if statement, that is then evaluated to be true or false

For example, to check if a is equal to 3, you use...

30
New cards

a is greater than or equal to 4

Output for the following:

a = 5

if a < 4:

print("a is less than 4")

else:

print("a is greater than or equal to 4")

31
New cards

If the "if" is true

The only time the "else" block won't execute

32
New cards

a = 5

if 4 <= a <= 10:

print("a is between 4 and 10")

else:

print("a is < 4 or > 10")

Print "a is between 4 and 10" or "a is < 4 or > 10" when a equals 5.

33
New cards

loops

A control structure for controlling the path through the code called ______. There are often times in our programs when we want to do something over and over and over until some condition is met.

34
New cards

x = 0

while x < 5:

x = x + 1

print(x)

Print x as "x+1" as long as x is less than 5.

35
New cards

while

Think of ______ as a repeating "if."

36
New cards

while my_str != "d" and my_str != "g":

print("not a valid selection")

Print "not a valid selection" if my_str is unequal to d and g.

37
New cards

import random

number = random.randint(0,100)

guess = int(input("Guess a number between 0 and 100: "))

Import Python's random number generator. Generate a random number, then prompt the user to guess a number between 0 and 100.

38
New cards

Import Python's random number generator. Generate a random number, then prompt the user to guess a number between 0 and 100.

If the guess was too high or too low, tell them, and prompt them to guess again. If the guess was correct, tell them, "that's it. the number was ___."

Explain the steps below:

import random

number = random.randint(0,100)

guess = int(input("Guess a number between 0 and 100: "))

numFound = False

while numFound == False:

if guess > number:

print("You guessed too high")

guess = int(input("Guess again: "))

elif guess < number:

print("You guessed too low")

guess = int(input("Guess again: "))

else:

print("That's it. The number was ", number)

numFound = True

39
New cards

iterator

A type of loop in Python that uses the keyword "for."

40
New cards

range

A type of collection that is a sequence of numbers, such as 1,2,3,4,5.

41
New cards

numbers = range(1,6)

Generate the sequence of numbers 1,2,3,4,5.

42
New cards

for x in range(1,6):

print(x * 2)

Multiply each number ("x") within the given range (of 1 to 5) by 2.

43
New cards

myList = ['a', 2, 'puppies', 4]

for item in myList:

print(item)

One of the other collection types we saw was a list. In a list, it's a collection of items that can be of different types and we can iterate over the list in the same way that we iterate over a string or a sequence

of numbers.

For example...