One of the exercises in my assignment is to make program which guesses a number:
min=1
max=10
count=1
answer=input("Think of af number between "+str(min)+" and "+str(max)+" and then press enter ")
while answer!="correct":
if min>max:
print("\nYou are cheating! Good bye.")
break
else:
guess=(min+max)//2
answer=input("My no."+str(count)+" guess is "+str(guess)+" - enter 'higher', 'lower' or 'correct': ")
if answer=="correct":
print("I guessed it!")
elif answer=="higher":
min=guess+1
count+=1
elif answer=="lower":
max=guess-1
count+=1
else:
print("\nCouldn't recognize your input, please try again.")
We have just been taught about exceptions, but I'm not really sure if it would make sense to use an exception in this case, maybe instead of the else statement?