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
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
© 2024 OneMinuteCode. All rights reserved.