有人能用python写出代码吗wwww

CSDN问答 2021-10-28 21:38:09

``#可以才五次import randomnum = random.randint(1,100)count=5while True: if count == 0: print('游戏失败') break guess=int(input('请猜数字：')) if guess == num: print('恭喜你答对了！') break elif guess > num: print('你输的值太大') elif guess < num: print('你输的值太小') count-=1``
``#可以一直猜import randomnum = random.randint(1,100)count=0while True: guess=int(input('请猜数字：')) count+=1 if guess == num: print('你猜了{}轮，终于成功了！'.format(count)) break elif guess > num: print('你输的值太大') elif guess < num: print('你输的值太小')``

``# 问题1import randomcount = 0goal = random.randint(1,101)while True: guess = int(input("请输入一个数字:")) if guess > goal: print("你输入的值太大!") elif guess < goal: print("你输入的值太小!") else: print("恭喜你答对了!") break count += 1 if count == 5: print("游戏失败") break``
``# 问题二import randomcount = 0goal = random.randint(1,101)while True: guess = int(input("请输入一个数字:")) count += 1 if guess > goal: print("你输入的值太大!") elif guess < goal: print("你输入的值太小!") else: print("你猜了 {} 轮,终于成功了.".format(count)) break``