Answer:
The complete program is as follows:
keepGoing = True
attempts = 0
correct = 2
while keepGoing:
guess = input("Guess an integer from 1 to 10: ")
guess = int(guess)
attempts = attempts + 1
if guess == correct:
print("You were correct!")
keepGoing = False
elif guess < correct:
print("Guess higher.")
else:
print("Guess lower. ")
Explanation:
This line initializes keepGoing to true
keepGoing = True
This initializes number of attempts to 0
attempts = 0
This initializes the correct guess to 2 (you can also use any number)
correct = 2
The following iteration is repeated until the number is guessed correctly
while keepGoing:
guess = input("Guess an integer from 1 to 10: ")
guess = int(guess)
attempts = attempts + 1
if guess == correct:
print("You were correct!")
If user guess is correct, keepGoing is set to False
keepGoing = False
elif guess < correct:
print("Guess higher.")
else:
print("Guess lower. ")