3507864055 发表于 2021-3-22 20:14:30

求帮助

import random

times = 3
secret = random.random(1,10)

print("我是一个游戏")
guess = 0
print("猜一猜我心中的数字",end"")

while (guess !=secret) and (times>0):
    temp = input()

    if temp.isdigit():
      guess = int(temp)
      if guess == secret:
            print("答对了,干得不错.")
      else:
            if guess > secret:
                print("大兄弟,大啦")
            else:
                print("大兄弟,小啦")
            if times > 0:
                print("请再试一试.",end"")
            else:
                print("你是在弱了")
    else:
      print("类型输入错误,请重新输入",end"")
    times = times-1
print("游戏结束")
照着打语法也错误,难受

Daniel_Zhang 发表于 2021-3-22 20:21:20

import random


times = 3
secret = random.randint(1, 10)# 不是 random 是 randint

print("我是一个游戏")
guess = 0
print("猜一猜我心中的数字", end="")# 逗号用英文的, 是 end = "" 不是 end ""

while (guess != secret) and (times > 0):
    temp = input()

    if temp.isdigit():
      guess = int(temp)
      if guess == secret:
            print("答对了,干得不错.")
      else:
            if guess > secret:
                print("大兄弟,大啦")
            else:
                print("大兄弟,小啦")
            if times > 0:
                print("请再试一试.", end="")# 是 end = "" 不是 end ""
            else:
                print("你是在弱了")
    else:
      print("类型输入错误,请重新输入", end="")# 逗号用英文的, 是 end = "" 不是 end ""
    times = times-1
print("游戏结束")

3507864055 发表于 2021-3-22 22:28:48

谢了,老是粗心。
页: [1]
查看完整版本: 求帮助