# [ ] 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 whole number to make a sum: ")
if int_input.isdigit():
int_input = int(int_input)
sum += int_input
else:
print(sum)
break
2
# [ ] 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 = "violet"
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
Harry is in the correct format !
# [ ] create a math quiz question and ask for the solution until the input is correct
solution = "84"
while True:
quiz = input("Enter the result of 42 times 2: ")
if quiz.isdigit() != True:
print("You have to enter a number solution. Try again")
elif quiz == solution:
print("\nCongrats!! 84 is correct.")
break
else:
print("Keep trying")
Congrats!! 84 is correct.
# [ ] 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 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")
you win!
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("Are potato chips good for you?","F")
quiz_item("Do you need to eat fruits and veggies?","T")
quiz_item("Do you need to drink at least 6 glasses of water per day?","T")
Try again