二手产品经理

二手产品经理

THIS IS RENO

Learn Python online for 100 days - Week 4, Day 1.

Record#

  1. Today I learned how to use import: its function is to load libraries or functions.
  2. random is a function that generates random numbers. The usage is random.randint(number1, number2), which returns a random number between the two given numbers.
  3. Modify the code of [[100 Days of Python - Day 18]] to not require inputting a fixed number, but instead generate a random number by the system.

CODE#

import random

print("Guess the Number Game!")
n0 = random.randint(0, 10000000)
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, this number is smaller than", n1)
        print()
        n2 += 1
        continue
    elif n0 > n1:
        print("Wrong guess, this 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.