Quick actions

cmd+k|ctrl+k

Navigation

Languages

Test

Snippet info

Language

Python

Visibility

public

Author

shirley

Created

2025-11-19T13:01:02.649155Z

Updated

2025-11-19T13:01:02.649155Z

print("Hello World!")
import random as random
print('Student Name: Chan Chui Mei')
n = random.randint(1,100)
while n > 0 :
    a = 1
    b = 100
    x = input(f"Please input a number from {a} to {b}: ")
    try:
        x = float(x)     
    except ValueError:
        print("Invalid Input!!! Please input a number")
    if x == "":
        print("No Input!!! Please input a number")
    if  float(x) < 1 and float(x) > 100:
        print(f'Please input a number within 1 to 100 ')
    if float(x) == n:
        print(f'Congratulations, The correct answer is {n}')
        break
    elif float(x) > n:
        b = float(x)
        print (f'Sorry, good try. The new range is {a} to {x}. Please try again!')
    elif float(x) < n: 
        a = float(x)
        print (f'Sorry, good try. The new range is {x} to {b}. Please try again!')
    


    
INFO