# [ ] use a "forever" while loop to get user input of integers to add to sum,
# until a non-digit is entered, then break the loop and print sum
sum = 0
while True:
user_int = input("Enter a number to add to the sum:")
if user_int.isdigit():
user_int = int(user_int)
sum += user_int
else:
print(sum)
break
# [ ] use a while True loop (forever loop) to give 4 chances for input of a correct color in a rainbow
# rainbow = "red orange yellow green blue indigo violet"
count = 0
rainbow = "red orange yellow green blue indigo violet"
while True:
color = input("Enter a color of the rainbow:")
if color in rainbow:
count += 1
if count == 4:
break
else:
print("enter only a valid color of the rainbow (ROYGBIV)")
break
# [ ] Get input for a book title, keep looping while input is Not in title format (title is every word capitalized)
title = ""
while True:
title = input("Enter a book title:")
if title == title.title():
break
else:
title = input("Enter a book title:")
# [ ] create a math quiz question and ask for the solution until the input is correct
answer = "9"
user_answer = input("What is 3 * 3?")
while answer != user_answer:
print("INCORRECT")
user_answer = input("What is 3 * 3?")
print("CORRECT: 3 * 3 = 9")
# [ ] review the code, run, fix the error
tickets = int(input("enter tickets remaining (0 to quit): "))
while tickets > 0:
# if tickets are multiple of 3 then "winner"
if int(tickets/3) == tickets/3:
print("you win!")
else:
print("sorry, not a winner.")
tickets = int(input("enter tickets remaining (0 to quit): "))
print("Game ended")
# Create quiz_item() and 2 or more quiz questions that call quiz_item()
def quiz_item(question, solution):
user_answer = input(question)
while True:
if user_answer.upper() != solution:
print("Incorrect!")
user_answer = input(question)
else:
print("Correct!")
break
q_1 = "(T/F): My brother once duck taped the elf on the shelf to our ceiling fan"
q_1_answer = "T"
quiz_item(q_1 , q_1_answer)
q_2 = "(T/F): I like mushrooms"
q_2_answer = "F"
quiz_item(q_2 , q_2_answer)