Reputation:
im a beginner with this so I just want to know how I could possibly call int(guess) later in the code?
from random import randint
from random import seed
for _ in range(1):
value = randint(0, 10)
print(value)
guess = input('guess a number 1-10 ')
if int(guess) == int(value):
print('gj')
if int(guess) >= int(value):
print('less!')
guess = input('guess a number 1-10 ')
if int(guess) <= int(value):
print('more!')
guess = input('guess a number 1-10 ')
Upvotes: 0
Views: 43
Reputation: 6190
from random import randint
value = randint(0, 10)
print(value)
while True:
guess = int(input('Guess a number 0-9'))
if guess == value:
print('Great job!')
break
if guess >= value:
print('less!')
if guess <= value:
print('more!')
There's a few things to say here:
for _ in range(1):
- that's a loop, but it will only ever go round the loop one time, so you don't need a loop at all.guess = int(input('Guess a number 0-9'))
and then you dont need to do int(guess)
everywhere else.while True
loop will make the program execute everything in that block forever - or until the break
statement is reached.Upvotes: 3