我正在编写一些代码,用于输出两个输入列表的值,对它们进行排序并显示它们。 我可以让它返回值,但它也返回一堆逗号。我浏览了StackOverflow和Reddit以找到不同的方法,但找不到有效的方法。有人可以看看我的代码,看看我在这里做错了吗?
if response == 'Combine':
def combo():
list1 = [numblist1]
list2 = [numblist2]
numblist1 = input('Enter your first list in the following format: [X,X,X,X] ---- ')
numblist2 = input('Enter your second list in the following format: [X,X,X,X] ---- ')
list3 = [list1+list2]
numblist4 = map(float, 'list3'.split(','))
return(sorted(numblist4))
由于某些原因,代码将在我运行时输出:
What would you like to do: Sift, Check, Sum, Reverse or Combine?Combine
Enter your first list in the following format: [X,X,X,X] ---- 1,4,3
Enter your second list in the following format: [X,X,X,X] ---- 4,6,5
(1, 4, 3) <---I have no idea why this is being displayed
[1, 3, 4] <---I have no idea why this is being displayed
[',', ',', ',', ',', '1', '3', '4', '4', '5', '6']
这就是一切......
print('-----------------------------------------------')
print()
print('Below is a short dictonary of this programs functions:')
print('Sift - Takes list and reduces all duplicated elements to single values.')
print('Check - Identifies wether or not the values are in the correct order.')
print('Sum - Adds values from list together and returns the sum of those values.')
print('Reverse - Returns elements from list in reversed order')
print('Combine - Combines elements from two list and returns them in single sorted list')
print()
response = input('What would you like to do: Sift, Check, Sum, Reverse or Combine?')
if response == 'Combine':
def combo():
list1 = [numblist1]
list2 = [numblist2]
numblist1 = input('Enter your first list in the following format: [X,X,X,X] ---- ')
numblist2 = input('Enter your second list in the following format: [X,X,X,X] ---- ')
list3 = [list1+list2]
numblist4 = map(float, 'list3'.split(','))
return(sorted(numblist4))
if response == 'Sum':
def add():
numblist1 = input('Enter your first list in the following format: [X,X,X,X] ---- ')
numblist2 = input('Enter your second list in the following format: [X,X,X,X] ---- ')
numblist3 = numblist1+numblist2
numblist1 = eval(numblist1)
print(numblist1)
print(sorted(numblist1))
print(sorted(numblist3)
答案 0 :(得分:0)
我有一些东西,我不确定这是不是你想要的,但现在是:
[A-Z]
我没有进行任何升级,如果你想让它成为功能,那么问我但很容易......你在那里做了一些疯狂的事情,也许我错过了一些你想要你的程序的功能如果是,那就问我他们:)