python不接受我的变量

时间:2016-04-09 17:22:01

标签: python

#dating sim
energy = 10
flirtpower = 5
print ('welcome to Paragonia dating simulator!')
print ('it is a sunny day at the end of the summer. You are new to
Paragonia Highschool.')
print ('A cute blonde boy walks up to you. he says:')
name = int (input ("what's your name?"))
print ('-Nice too meet you, ' name ,'! My name is Alex, Alex Snowdon.
He smiles at you.')

python说'语法无效'并突出显示变量' name'。我究竟做错了什么?我是一个完全的初学者......

3 个答案:

答案 0 :(得分:1)

您在变量name

之前忘记了逗号
print ('-Nice too meet you, ', name ,'! My name is Alex, Alex Snowdon. He smiles at you.')

此外,您将面临另一个错误,因为您正在向int投射我认为您想要str的输入:

更改此内容:name = int (input ("what's your name?"))

要:

name = input ("what's your name?")

更简单的方法是写这个来避免这样的问题,就是在字符串上使用format,并将{}放在要放置变量的位置:

print ('-Nice too meet you, {}! My name is Alex, Alex Snowdon. He smiles at you.'.format(name))

答案 1 :(得分:0)

print ('-Nice too meet you, ', name ,'! My name is Alex, Alex Snowdon. He smiles at you.')
#You forgot a comma here     ^, and you cannot put a string over multiple lines, 
unles you use triple-commas, like this:

"""This is a string
that goes over multiple lines."""

答案 2 :(得分:0)

在这一行

print ('-Nice too meet you, ' name ,'! My name is Alex, Alex Snowdon.
He smiles at you.')

你忘了带来一个后来' - 也见到你了,' [在这里插入昏迷]名字,......

相关问题