我正在制作一个调度程序,它通过用户的名称来获取用户的输入,用户可以访问的作业以及这些作业是什么类型的。我的问题是,如果#of jobs==4,那么,类jobs应该提示用户4次,但由于它们都在各自的函数中,#of jobs重置,这使得类jobs只提示一次
我尝试过的是,将它们组合在一个函数中,这样作业的#就不会重置并生成for循环,而是显示4次,而不是提示用户
How many jobs do you have access in? (1-4): 2
---------------------------------------------------------------------------
Please, TYPE: SMT, TEST, REWORK, BOX BUILD, SHIPPING & WASH: wash
---------------------------------------------------------------------------
['Marc', 'WASH']
---------------------------------------------------------------------------
['Marc', 'WASH', 'WASH']
---------------------------------------------------------------------------
None
---------------------------------------------------------------------------
预期结果是:
How many jobs do you have access in? (1-4): 2
---------------------------------------------------------------------------
Please, TYPE: SMT, TEST, REWORK, BOX BUILD, SHIPPING & WASH: SMT
---------------------------------------------------------------------------
Please, TYPE: SMT, TEST, REWORK, BOX BUILD, SHIPPING & WASH: TEST
---------------------------------------------------------------------------
["SMT","TEST"]
---------------------------------------------------------------------------
full_employee = []
def employee_name_input():
while True:
employee_name = str(input("Enter your first name: ")).strip().capitalize()
if not employee_name.isalpha():
print("Invalid input. Please try again!")
else:
full_employee.insert(0,employee_name)
return access_jobs_input()
def access_jobs_input():
access_num = int(input("How many jobs do you have access in? (1-4): "))
if access_num <= 4:
access_jobs = str(input("Please, TYPE: SMT, TEST, REWORK, BOX BUILD, SHIPPING & WASH: ")).strip().upper()
for num in range(access_num):
full_employee.append(access_jobs)
print(full_employee)
if not access_jobs.isalpha():
print("Your input is invalid. Please try again")
return access_jobs_input()
else:
print ("You are entering more than 4 access and it is not authorized. Please try again!")
return access_jobs_input()
你的代码有一些问题,我将在下面概述
access_num
次,但只需添加一次李>access_num
次,并且对于无效的输入李>full_employee
,并实际调用函数使其工作isalphanum
employee_name_input
函数应该返回一个字符串isalpha
for name将不起作用,除非您只希望名字中没有空格下面的代码应该适合您。查看评论以了解发生了什么
可能的输出将是
相关问题 更多 >
编程相关推荐