初学者程序帮助Python3字符串不能调用?

2024-04-25 17:51:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在开发一个简单的程序,允许用户输入他们的名字和生日,机器人会根据用户的输入键入不同的响应。你知道吗

在我修补底部的#之前,我已经让程序运行了,但现在它不工作了。你知道吗

这是我的第一个节目,所以任何帮助都太好了!努力自学(这很难)

我试图将变量设置为用户输入的值。我让整个程序在一个点上工作,但我不知道发生了什么或错误的意思

Code

Error Message


Tags: 用户程序程序运行键入错误机器人名字节目
2条回答

我把它清理了一点,效果很好。你知道吗

name = input("What's your name? ")
print("Hello " + name + ", my name is Sam.")

my_birthday1 = "06.04"
my_birthday2 = "06/04"
birthday = input("What day of the year is your birthday? ")

if str(birthday) == my_birthday1 or str(birthday) == my_birthday2:
    print(birthday + " is also my birthday.")
else:
    print(birthday + "! That's cool!")

要在Python中指定字符串,请执行以下操作:

my_birthday1 = "whatever"

而不是

my_birthday1 = ("whatever")

因为defName("abc")用于调用某个函数defName并将"abc"传递给它。你知道吗

相关问题 更多 >