i have this below i have watched in and practiced a tutorial, however i tired to achieve the same outcome in a different logic and it has not been fairly correct. i need help with the code.
Code one allows me to get feed back if certain conditions are met, i tired the same method with code two but its not giving back the right results
Code 1
num = 32
tries = 3
guess = input("guess a number btn 1 and 50: ")
guess = int(guess)
while guess != num and tries != 0:
guess = input("guess a number btn 1 and 50: ")
guess = int(guess)
if guess == num:
print(âCongratulationsâ)
elif guess != num and tries == 1:
print(âBetter luck next timeâ)
break
elif guess > num:
tries -= 1
print(âGuessed too highâ)
else:
tries -= 1
print(âGuessed too lowâ)
please ask for further clarifications if its not explain well:
Code 2
def get_age():
age = ââ
tries = 3while age.isdigit() == False and tries != 0: age = input("Your age is? ") if age.isdigit() == True: print(age) elif age.isdigit() == False and tries == 1: print("Better luck next time") break elif age.isdigit() == False: tries -= 1 return int(age)
get_age()
other ways i tried in images: