60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
import sys
|
|
filename = sys.argv
|
|
|
|
def input_and_calculate_one_line():
|
|
printable_list = []
|
|
|
|
input_numbers = input("""Enter the numbers for summing (seperated by space), or enter "q" to exit.
|
|
""")
|
|
# print (input_numbers)
|
|
|
|
if input_numbers == "q":
|
|
return ""
|
|
else:
|
|
splitting_converting_summing_printing(input_numbers)
|
|
|
|
def splitting_converting_summing_printing(input_numbers):
|
|
split_numbers = input_numbers.split()
|
|
print (split_numbers)
|
|
|
|
converted_list = list(map(int, split_numbers))
|
|
print (converted_list)
|
|
|
|
summed_numbers = sum(converted_list)
|
|
print (summed_numbers)
|
|
|
|
|
|
printable_list = intersperse(converted_list, "+")
|
|
|
|
list_with_strings = convertListElementsToStr(printable_list)
|
|
|
|
converted_to_strings_list = listToString(list_with_strings)
|
|
print (converted_to_strings_list, "=", summed_numbers)
|
|
|
|
|
|
# for i in converted_list:
|
|
|
|
# printable_list.append(i)
|
|
# printable_list.append("+")
|
|
# printable_list += str(i)
|
|
# printable_list += '+'
|
|
|
|
def intersperse(lst, item):
|
|
result = [item] * (len(lst) * 2 - 1)
|
|
result[0::2] = lst
|
|
return result
|
|
|
|
def convertListElementsToStr(list):
|
|
# how_long = len
|
|
# result = []
|
|
result = map(str, list)
|
|
# result.append[str(i) for i in list]
|
|
return result
|
|
|
|
def listToString(s):
|
|
str1 = " "
|
|
return (str1.join(s))
|
|
|
|
|
|
input_and_calculate_one_line()
|
|
|