死循环不限次数猜测
import random
robot = random.randint(0, 101)
print(f'不要看,最后答案是:{robot}')
n =1
while True:
user =int(input("请输入数字:"))
if user > robot:
print(f'第{n}次,猜大了')
elif user < robot:
print(f'第{n}次,猜小了')
else:
print(f'第{n}次,猜对了')
break
n +=1
限制次数
print('给你3次机会赢过我')
n =1
while n <4:
robot = random.choice(["石头", "剪刀", "布"])
print(robot)
user =input(f'第{n}次游戏,请猜拳,输入剪刀/石头/布:')
if user =="石头" and robot =="剪刀" or user =="剪刀" and robot =="布" or user =="布" and robot =="石头":
print(f'你赢了,放过你')
break
elif user =="石头" and robot =="布" or user =="剪刀" and robot =="石头" or user =="布" and robot =="剪刀":
print(f'你输了,还剩{3-n}次机会')
else:
print(f'平局再来,还剩{3-n}次机会')
n +=1
if n >=4:
print("机会用光")
else:
pass