Crossin的编程教室

标题: python入门第40课中出现“未终止的字符串文字”... [打印本页]

作者: 小刘    时间: 2021-11-17 15:17
标题: python入门第40课中出现“未终止的字符串文字”...
本帖最后由 小刘 于 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行中未终止的字符串文字”的反馈
希望能有大神指点指点


作者: crossin先生    时间: 2021-11-17 23:49
  1. 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))
复制代码
这是一行代码,因为过长而在网页上显示为两行,你不要人为地分成两行
如果要分行,你也在引号之后 %之前换行,不然你换在了引号之内,硬生生把一个字符串跨行了,不符合语法
作者: 小刘    时间: 2021-11-18 08:45
crossin先生 发表于 2021-11-17 23:49
这是一行代码,因为过长而在网页上显示为两行,你不要人为地分成两行
如果要分行,你也在引号之后 %之前换 ...

噢噢噢噢哦哦哦 明白了 感谢crossin先生




欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/) Powered by Discuz! X2.5