Python 正在尝试使用多个输入打印,但输入的内容不足
我已经写了一个代码,打印出包含变量的文本墙,一旦变量输入正确,代码就会正常工作。我试图在python idle中的一行中输入多个变量。我使用split函数来实现这一点,它只检测到一个输入 我已多次尝试输入此信息: 10.2.1 ACT10p2_任务1_团队4D_模板.py 2019年10月30日Caleb.Kunz不适用4D标题。代码Python 正在尝试使用多个输入打印,但输入的内容不足,python,input,Python,Input,我已经写了一个代码,打印出包含变量的文本墙,一旦变量输入正确,代码就会正常工作。我试图在python idle中的一行中输入多个变量。我使用split函数来实现这一点,它只检测到一个输入 我已多次尝试输入此信息: 10.2.1 ACT10p2_任务1_团队4D_模板.py 2019年10月30日Caleb.Kunz不适用4D标题。代码 activity, task, file, date, name, section, team, description = input("Type Activi
activity, task, file, date, name, section, team, description = input("Type Activity, Task, File, Date, Name, Section, Team, Description ").split(),
print(" # Activity {0} Task {1}\n".format(activity, task),
"# File: {0}\n".format(file),
"# Date: {0}\n".format(date),
"# By: {0}\n".format(name),
"# Section: {0}\n".format(section),
"# Team: {0}\n".format(team),
"# \n",
"# ELECTRONIC SIGNATURE\n",
"# {0}\n".format(name),
"# \n",
"# The electronic signature above indicates the script\n",
"# submitted for evaluation is my individual work, and I\n",
"# have a general understanding of all aspects of its\n",
"# development and execution.\n",
"# \n",
"# Description: {0}\n".format(description))
我希望输出是一个文本墙,使用输入在正确的位置打印墙。相反,它说它没有收到足够的输入如果在
split()
的末尾有一个尾随逗号,则整个语句将成为一个元组。删除逗号即可生效。如果要按逗号拆分,请尝试此操作:
activity, task, file, date, name, section, team, description = input(
"Type Activity, Task, File, Date, Name, Section, Team, Description ").split(',')
print(" # Activity {0} Task {1}\n".format(activity, task),
"# File: {0}\n".format(file),
"# Date: {0}\n".format(date),
"# By: {0}\n".format(name),
"# Section: {0}\n".format(section),
"# Team: {0}\n".format(team),
"# \n",
"# ELECTRONIC SIGNATURE\n",
"# {0}\n".format(name),
"# \n",
"# The electronic signature above indicates the script\n",
"# submitted for evaluation is my individual work, and I\n",
"# have a general understanding of all aspects of its\n",
"# development and execution.\n",
"# \n",
"# Description: {0}\n".format(description))
测试:测试1、测试2、测试3、测试4、测试5、测试6、测试7、测试8
Type Activity, Task, File, Date, Name, Section, Team, Description test1,test2,test3,test4,test5,test6,test7,test8
# Activity test1 Task test2
# File: test3
# Date: test4
# By: test5
# Section: test6
# Team: test7
#
# ELECTRONIC SIGNATURE
# test5
#
# The electronic signature above indicates the script
# submitted for evaluation is my individual work, and I
# have a general understanding of all aspects of its
# development and execution.
#
# Description: test8
这是因为您正在为
输入设置8个变量。如果键入所有变量,则这是您的输出:
Type Activity, Task, File, Date, Name, Section, Team, Description activity, task, file, date, name, section, team, description
# Activity activity, Task task,
# File: File, # Date: date, # By: name,
# Section: section,
# Team: team,
#
# ELECTRONIC SIGNATURE
# name,
#
# The electronic signature above indicates the script
# submitted for evaluation is my individual work, and I
# have a general understanding of all aspects of its
# development and execution.
#
# Description: description
您应该考虑使用类或函数来设置属性。