我在写一个程序,让用户输入填写两个列表,每个列表有3个整数(总共6个),然后打印两个排序的列表并合并。如何让我的程序在列表之间切换并向用户请求整数?这就是它的工作原理:
Please enter a value for listone:
Please enter a value for listtwo: # instead I have listone displayed 3 times
Please enter a value for listone:
Please enter a value for listtwo:
这是我目前的代码:
def user_input():
listone = []
listtwo = []
listone_value = int(input("Please enter a value for listone: "))
for i in range (2):
listone_value = int(input("Please enter a value for listone: "))
listtwo_value = int(input("Please enter a value for listtwo: "))
for i in range(2):
listtwo_value = int(input("Please enter a value for listtwo: "))
def merge_lists(listone, listtwo):
list = []
while listone and listtwo:
L.append( listone.pop(0) if listone[0] < listtwo[0] else listtwo.pop(0) )
L.extend(listone if listone else listtwo)
return list
我只是不知道如何让问题交替,因为我还是比较新的程序。你知道吗
如果您确切地知道需要多少输入,只需使用for循环
相关问题 更多 >
编程相关推荐