user14173601
user14173601

Reputation:

python guessing game int calling

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

Answers (1)

Tom Dalton
Tom Dalton

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:

  1. You don't need your original 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.
  2. You can do guess = int(input('Guess a number 0-9')) and then you dont need to do int(guess) everywhere else.
  3. Using a while True loop will make the program execute everything in that block forever - or until the break statement is reached.

Upvotes: 3

Related Questions