0
[python] I can't make my {i} count in my code .Please give me some solution.
import random number = random.randint(1,2) print("Here's the question\nI'm looking for a number from 1 to 2 ") guess_num = int(input("Enter a number :")) def guessing_func(guess_num): i = 0 while guess_num != number : if guess_num < number : print("guess higher ") guess_num = int(input("Try again :")) i+=1 return guessing_func(guess_num) elif guess_num > number : print("guess lower ") guess_num = int(input("Try again :")) i+=1 return guessing_func(guess_num) elif guess_num == number : i += 1 break print("You got it ,the number is {0} . \nYou have tried {1} times".format(number , i )) guessing_func(guess_num)
2 Respuestas
+ 5
Your code is correct, unfortunately CodePlayground does not support the interactivity that you created. CodePlayground wants all inputs at the beginning of the program.
+ 3
If the number is right, you don't enter the loop so your i is 0. If you do enter the loop, you recurse and don't enter that loop.