Dec-22-2019, 07:46 PM
(This post was last modified: Dec-22-2019, 07:46 PM by H0M1C1D4L_P1G.)
Okay so I have managed to resolve the problem; I just changed some of the typecasting and such, because I had forgotten that when a variable's value is determined by an input, it is automatically regarded as a string. Here is the finished code:
>>> attempts=0;guess=0;number=random.randint(1,100) >>> while int(guess)!=number: ... if int(attempts)<1:guess=input('Feeling lucky? Take a guess!\n');attempts+=1 ... elif int(guess)>number:guess=input('Too high! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1 ... elif int(guess)<number:guess=input('Try a bit higher! Would you like to try again?\nEnter a number = Yes Alt + F4 = No\n');attempts+=1 ... else: ... if attempts<5:print('Congratulations! That only took you '+str(attempts)+' attempts - pretty impressive!') ... elif int(attempts)<10:print('It took you '+str(attempts)+' tries, but you got there eventually!') ... else:print('Gosh! '+str(attempts)+' guesses?! It\'s not your lucky day.');print(input('How long did you spend trying?\n')+'? Lol')Also, ichabod801, when you say not to use ; to put multiple commands in one line, where I have lines like
if int(attempts)<1:guess=input('Feeling lucky? Take a guess!\n');attempts+=1I was unsure how to put the
attempts+=1section in a separate line with accurate syntax. Could you give me an example of how to do this? Also any optimisation (or general) tips would be appreciated.