- 帖子
- 4
- 精华
- 0
- 积分
- 24
- 阅读权限
- 10
- 注册时间
- 2021-10-11
- 最后登录
- 2021-11-20
|
本帖最后由 小刘 于 2021-11-17 15:20 编辑
代码如下:
import random
key = random.randint(0,100)
num = key
f = open("gamescore.txt")
score = f.read().split()
f.close()
game_times = int(score[0])
min_times = int(score[1])
total_times = int(score[2])
if game_times > 0:
avg_times = total_times / game_times
else:
avg_times = 0
print("You already played %d times, guess the answer at least %d round, guess the answer in an average of %.2f rounds
" % (game_times, min_times, avg_times))
print("Guess a number.")
bingo = False
while bingo == False:
times += 1
answer = int(input())
if answer < num:
print("Too small!")
if answer > num:
print("Too big!")
if answer == num:
print("BINGO! %s is the right answer!"%num)
bingo = True
if game_times == or times < min_times:
min_times = times
total_times += times
game_times += 1
result = "%d %d %d" % (game_times, min_times, total_times)
f = open("gamescore.txt", "w")
f.write(result)
f.close()
跑代码时出现“第18行中未终止的字符串文字”的反馈
希望能有大神指点指点
|
|