我目前正在开发一个处理用户输入的程序,我遇到了一个情况,在一个input()
下需要多个返回,一开始我不知道当我得到一个值错误时我在做什么,直到我查了怎么做,它向我展示了这一点,并且在使用input().split()
的两个输入时运行良好
class userinput():
def __init__(self, name,lista,listb,listc,listd):
self.name=""
self.lista=lista
self.listb=listb
self.listc=listc
self.listd=listd
def set_lists(self):
print("Do you want to create lists")
decision = input()
if decision == "yes":
print("how many lists would you like to create?(up to 4)")
decision2= int(input())
if decision2 == 1:
print("what would you like the list to be named")
self.lista=input()
print("you have created 1 list, with the name:"+ self.lista)
elif decision2 == 2:
print("what would you like your lists to be?")
self.lista,self.listb=input().split(",")
print("You have created 2 lists with the names," + self.lista ,self.listb)
elif decision2 == 3:
print("what name would you like your first 2 lists to be")
self.lista,self.listb = input().split(",")
print("finally, the name for your third")
self.listc = input()
print("you have created 3 lists with the names," +self.lista,self.listb,self.listc)
elif decision2 == 4:
print("what name would you like your first 2 lists to be")
self.lista,self.listb = input().split(",")
print("finally, for your last 2 lists")
self.listc,self.listd=input().split(",")
print("you have created three lists with the names of," +self.lista,self.listb,self.listc,self.listd)
else:
print("quitting")
return
else:
print("quitting")
我的问题:似乎没有必要对4个输入使用2input().split()
,有没有必要清理?
目前没有回答
相关问题 更多 >
编程相关推荐