二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 3 Day 4

Record#

  1. Today's practice is a comprehensive exercise on while and if.
  2. Writing a number guessing game, today's writing went smoothly, and there are no logical issues. The only minor problems are the aesthetics and the consideration of the number of guesses.

CODE#

print("Number guessing game!")
n0 = 16832
n2 = 0
while True:
    n1 = int(input("Please enter a number between 0 and 10000000:"))
    if n1 < 0 or n1 > 10000000:
        exit()
    if n0 < n1:
        print("Wrong guess, the number is smaller than ", n1)
        print()
        n2 += 1
        continue
    elif n0 > n1:
        print("Wrong guess, the number is larger than ", n1)
        print()
        n2 += 1
        continue
    else:
        print("Congratulations, you guessed it right. You guessed", n2, "times")
        break

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.