Make an integer variable with the name cookie and the value 3
cookie = 3
Given an integer x, make a variable cube and assign it the value of x cubed.
cube = x ** 3
Given a string variable penguin, print that variable with an ! at the end using concatenation
print(penguin + "!")
Make a variable is_good with the value True
is_good = True
Assume you have a function elsewhere called shenanigans that takes no parameters. Call this function.
shenanigans()
Make a string variable with the name year and the value 2025
year = '2025'
Add parentheses to the following so that value is equal to 6:
value = 3 * 3 - 1
value = 3 * (3 - 1)
Given an integer variable bob, repeat the word hello repeated bob times.
print(bob * "hello")
Without using logical operators, write an expression that will evaluate to True if some variable apple is NOT equal to another variable banana
apple != banana
Assume you have a function update_word that takes a string parameter and returns a different string. Pass this function the parameter "hello" and print the result
print(update_word("hello"))
Make a variable cake with a value provided by the user
cake = input("Enter a value: ")
Assume you have integer variables red and blue. Write an expression that calculates the remainder of red divided by blue.
red % blue
Given a string variable sandwich, print the string in all uppercase letters.
print(sandwich.upper())
Write an expression using the not operator that is equivalent to x < 3
not x >= 3
Write a function called square_this that takes a single int parameter x. It returns the square of x.
def square_this(x): return x ** 2
Make a variable potato with an integer value provided by the user
potato = int(input("Enter an integer value: "))
Import the math module
import math
Given a string variable flower, make a new variable called petal that is just the first and last letter of flower
petal = flower[0] + flower[-1]
Given a string variable word, write an expression that will evaluate to True if the word has more than 5 characters AND the word starts with lowercase k
len(word) > 5 and word[0] = 'k'
Write a function called greet that takes a single parameter called name. The function prints the message "Good morning, <name>!" but with the name replaced with the given value.
def greet(name): print(f"Good morning, {name}!")
Given two variables named cat and dog, print an f-string containing the two variables
print(f"My pets are {cat} and {dog}")
Assume you've already imported the math module, and that you have a variable called degrees. Write an expression that calculates the sine of degrees.
math.sin(math.radians(degrees))
Write an expression that counts the number of letter P's in the phrase "purple hippopotamus"
"purple hippopotamus".count("p")
Given two float variables abcd and efgh, write a code snippet that will print "Yay" if they are equal or "Nay" if they are not.
if abcd == efgh: print("Yay") else: print("Nay")
Write a function first_and_last that takes a single string parameter password. If the first and last character of password are the same character, return the number 3. Otherwise, return the number 0.
def first_and_last(password): if password[0] == password[-1]: return 3 else: return 0