Files
PythonGame/game1.py
2025-07-07 22:09:55 +08:00

24 lines
763 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import random
def game1():
numbers = random.randint(1, 100)
print("我已经想好了1-100的任意一个数你能猜到是哪个吗")
while True:
try:
user_number = int(input("请输入你的猜测数字:"))
if user_number>100 or user_number<1:
print("请输入一个1-100的数字")
elif user_number>numbers:
print("你的数字太大了")
elif user_number<numbers:
print("你的数字太小了")
else:
print(f"恭喜你猜对了,这个数字是{numbers}")
break
except ValueError:
print("请输入一个有效的数字。")
if __name__ == '__main__':
game1()