嘿伙计们,我一直在使用 Python 时遇到语法错误,这是我第一天使用 Python,请给我宽限期

问题描述 投票:0回答:1

我正在尝试做一个 madlib 游戏并不断出现语法错误,但我正在观看视频但得到完全不同的结果。

我试图消除错误,但它继续转到下一个光标

疯狂库(): 打印(“欢迎来到我疯狂的图书馆”)

pronoun1=input ("fans")
first name=input ("jeremy")
noun1=input ("tree")
last name=input ("thomas")
second pronoun=input("stars")
place=input ("broward")
third pronoun=input ("lions")
place2=input ("LA")
fourth pronoun=input("moons")
noun2=input ("chair")
adjective1=input("sharp")
adjective2=input("smelly")
verb=input("fighting")
adjective3=input("tall ")

print "hello there, sports",pronoun1, "this is" first name"talking to you from the press" noun1 "in" last name "stadium, where 57,000 cheering" second pronoun "have gathered to watch the" place third pronoun "take on the"  place 2 fourth pronoun "even though the"  noun2 "is shining, its a" adjective1 "cold day with the temperatrue in the" adjective2 "2os. We'll be back for the opening " verb "after a few words from our" adjective3 "sponsor"
python syntax madlib
1个回答
1
投票

在要求输入的行中,变量名称中不应包含任何空格。而不是名字,你应该使用 first_name,像这样:

first_name = input("Jeremy")

在末尾的打印语句中,您应该在要打印的字符串周围使用括号。此外,您在尝试连接字符串的几个地方缺少加号。这是打印语句的更正版本:

print("Hello there, sports " + pronoun1 + ", this is " + first_name + " talking to you from the press " + noun1 + " in " + last_name + " Stadium, where 57,000 cheering " + second_pronoun + " have gathered to watch the " + place + " " + third_pronoun + " take on the " + place2 + " " + fourth_pronoun + ". Even though the " + noun2 + " is shining, it's a " + adjective1 + " cold day with the temperature in the " + adjective2 + " 20s. We'll be back for the opening " + verb + " after a few words from our " + adjective3 + " sponsor.")

这些更改应该有助于消除代码中的语法错误。

还要记得像这样在第一行导入madlib:

import madlib

希望这对您的项目有所帮助,祝您好运!

© www.soinside.com 2019 - 2024. All rights reserved.