+ 1

Can anyone help me with this code pleas

Guess the number game: I want to add to the code how many times it took to guess the number. Like: Welldone, you guessed it in 7 times.

26th Oct 2023, 8:47 PM
Buzi Chaban
Buzi Chaban - avatar
6 Antworten
+ 3
Buzi Chaban , The code you pasted in your comment has no indentations. Assuming you fix the indentations, you'll need these three lines. I'll let you figure out where to put each one. guesstimes = 0 guesstimes += 1 print("Well done. You guessed it in", guesstimes, "guesses.")
27th Oct 2023, 3:32 PM
Rain
Rain - avatar
+ 7
You just need to add an ordinary counter to the loop that will add 1 each time the loop is executed and output the result under a positive condition...😎
26th Oct 2023, 10:15 PM
Solo
Solo - avatar
+ 6
Buzi Chaban , additionally (to the already mentioned issues) the following ones also has to be fixed: (line counting includes empty lines) line 3: declaration / initilization requires a value line 6: closing parenthesis missing line 6, 9, 11, 13: wrong kind of quotes around the strings
27th Oct 2023, 3:59 PM
Lothar
Lothar - avatar
+ 2
thankyou for the help guys I got it import random te_raden = random.randint(1,100) guesstimes = 1 while True: number = int(input(“Guess the number: “) if(number != te_raden): guesstimes += 1 if(number > te_raden): print(“To high”) elif(number < te_raden): print(“to low”) elif(number == te_raden): print(“you guessed the number”) break
27th Oct 2023, 7:45 PM
Buzi Chaban
Buzi Chaban - avatar
+ 1
Buzi Chaban , forgot to write the counter output...😎
27th Oct 2023, 9:36 PM
Solo
Solo - avatar
0
#this is what I have so far import random te_raden = random.randint(1,100) guesstimes = while True: number = int(input(‘Guess the number: ‘) if(number > te_raden): print(‘To high’) elif(number < te_raden): print(‘to low’) elif(number == te_raden): print(‘you guessed the number’) break
26th Oct 2023, 8:52 PM
Buzi Chaban
Buzi Chaban - avatar