I have a number game question.

Asked 2 years ago, Updated 2 years ago, 18 views

from random import randint

number = randint(1, 100)
print("Guess the number from 1 to 100" number)
count = 0

while True:
    x = int (input ("Enter a number: ")))
    count += 1
    if x == number:
        break
    elif x < number:
        print("{}" Re-match a number greater than:"format(x))
    elif x > number:
        print("{}" Please try again with a lower number:"format(x))

if x == number:
    print("Congratulations". Number of attempts =",count)

First of all, I want to run the "Enter a number:" part only once, but I don't know what to do. Second, if you enter a number that violates the previous mistake, I would like to end the repetition and print out a message saying, 'Failed.' They say we can use the lowerbound and upperbound commands, but I don't know what to do.

python

2022-09-20 10:28

1 Answers

Is this what you want?

from random import randint

number = randint(1, 100)
print("Guess the number from 1 to 100" number)
count = 0

x = int (input ("Enter a number: ")))
while True:
    count += 1
    if x == number:
        break
    elif x < number:
        x = int (re-match a number greater than "{}" ": ".format(x)))")
    elif x > number:
        x = int (re-match a number lower than "{}" ": ".format(x)))")

if x == number:
    print("Congratulations". Number of attempts =", count)
10


2022-09-20 10:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.