# [ ] 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:
int_input = input("Enter a set of numbers and enter exit when finished: ")
if int_input.isdigit():
int_input = int(int_input)
sum += int_input
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"
correct_color = "red"
num_guess = 4
while num_guess > 0:
color_guess = input("Guess a color found in a rainbow\n(red, orange, yellow, green, blue, indigo, or violet):").lower()
if color_guess == correct_color:
print("You guessed right.\n",correct_color,"is the correct color")
break
else:
num_guess -= 1
# [ ] Get input for a book title, keep looping while input is Not in title format (title is every word capitalized)
title = ""
while True:
book = input("Enter a correct book title (the first letter of each word should be capitalized): ")
if book.istitle():
print(book, "is in the correct format !")
break
else:
title += book
# [ ] create a math quiz question and ask for the solution until the input is correct
solution = "150"
while True:
quiz = input("Enter the result of 75 times 2: ")
if quiz.isdigit() != True:
print("You have to enter a number solution. Try again")
elif quiz == solution:
print("\nNice Job!! 150 is correct.")
break
else:
print("Keep trying")
# [ ] review the code, run, fix the error
tickets = 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):
answer = input(question)
while True:
if answer == solution:
return True
break
else:
print("Try again")
answer = input(question)
quiz_item("2 + 2 = 5","f")
quiz_item("popcorn is not very healthy to eat","t")
quiz_item("some birds are bigger than humans","t")