Given a string variable scary_chant, write a line of code to print scary_chant repeated 7 times.
print(scary_chant * 7)
Given a list called goodies, write a boolean expression that evaluates to False if the string "candied apple" is in goodies, and evaluates to True if it is not.
"candied apple" not in goodies
Create an infinite while loop
while True:
# loop bodyGiven a list called scary_movies, write an expression to get the index of the value "The Shining". (You can assume it exists in the list)
scary_movies.index("The Shining")
Write a for loop that prints each character in the word "halloween" one at a time.
for ch in "halloween":
print(ch)Ask the user for an integer, then print the cube of that number.
num = int(input("Give an int: "))
print(num ** 3)Given a list bat_sizes, write an expression that will evaluate to True if the final value in the list is either 3 or 7.
bat_sizes[-1] == 3 or bat_sizes[-1] == 7
Write a while loop that repeatedly prompts the user to type the letter "C" until the user does so.
user_input = input("Type C: ")
while user_input != "C":
user_input = input("Type C: ")Assume you have a function get_monsters that takes no parameters and returns a list. Call that function, then change the value of the 3rd item to "yeti"
monsters = get_monsters() monsters[2] = "yeti"
Write a for loop that prints the numbers 0 to 20 (not including 20) one at a time.
for i in range(20):
print(i)Write a function called look_for_ghosts that takes a string as its parameter. If the substring "ghost" is anywhere in the parameter, return True. Otherwise, return False.
def look_for_ghosts(s):
return "ghost" in sGiven a float spooky_level, print "Too scary!" if spooky_level is greater than 9. Otherwise, do nothing.
if spooky_level > 9:
print("Too scary!")Using a while loop, print the word "boo" 5 times, once on each line.
x = 5
while x > 0:
print("boo")
x = x - 1Given a list of strings called spell_ingredients, write an expression that connects all the strings into a single string using plus signs, e.g. "pumpkin+eye of newt+worm+quartz"
"+".join(spell_ingredients)
Given a list of integers ghoul_count, write a for loop that prints the index of each value greater than 10.
for i in range(len(ghoul_count)):
if ghoul_count[i] > 10:
print(i)Given a float variable spooky_angle, calculate the sine of that angle and assign it to a variable (assume the angle is in degrees)
import math spooky_sin = math.sin(math.radians(spooky_angle))
Assume you have two functions trick and treat, which each take no parameters and return nothing. Ask the user "Trick or treat". If the user chooses "treat" (in any combination of upper or lowercase), call the treat function. Otherwise, call the trick function.
choice = input("Trick or treat! ").lower()
if choice == "treat":
treat()
else:
trick()Assume you have a function are_you_haunted that takes no parameters and returns a boolean. Continuously call the function and print the message "Don't look behind you" until the function returns False.
while are_you_haunted():
print("Don't look behind you")Ask the user for a comma-separated list of their favorite cryptids. Convert this input into the list data type.
user_input = input("Enter your favorite cryptids")
cryptid_list = user_input.split(',')Assume you have an integer variable x. Write a loop to create a list of all positive odd numbers up to x (including x, if it's odd).
odd_list = []
for i in range(1, x + 1, 2):
odd_list.append(i)Write a function ghost_talk that takes a string parameter. It prints a version of that string where each o has been replaced by three o's. E.g. "Hello" will print "Hellooo"
def ghost_talk(s):
print(s.replace("o", "ooo"))Assume you have a function cast_spell that takes a string parameter and returns an int. Call the function on both "vampire" and "werewolf". If the results are the same, print "same". Otherwise, print the string that got the higher result.
vampire_result = cast_spell("vampire")
werewolf_result = cast_spell("werewolf")
if vampire_result == werewolf_result:
print("same")
elif vampire_result > werewolf_result:
print("vampire")
else:
print("werewolf")Write a while loop that continuously asks the user to input a positive integer and prints a running total of all the numbers that the user has entered so far. Leave the loop when the user enters anything else.
total = 0
next = input("Enter an int: ")
while next.isdigit():
total = total + int(next)
print(total)
next = input("Enter the next int: ")Assume you have a list called costume_ranking. Ask the user for a new costume and its rank, then insert it into the list at that rank. e.g. if the user enters "mummy" and 1, "mummy" should become the first item in costume_ranking.
costume = input("Enter a costume: ")
rank = int(input("Enter its rank: "))
costume_ranking.insert(rank - 1, costume)Assume you have a list of integers called candy_count. Calculate the average of all the numbers in candy_count.
sum = 0
for count in candy_count:
sum = sum + count
average = sum / len(candy_count)