4 Respuestas
+ 4
As the elements of the list are numbers in string dataformat, you can do this:
- create a variable like sum_
- use a for loop that can iterate over the list. like: for i in lst:
- you will get in each iteration an element from the list in loop varibale "i"
- covert this value in i with int(i) to integer and add it to a variable that holds the sum of all converted numbers
- after iteration is finished you have the sum of all values in the variable sum_ that can be printed
+ 4
if you mean something like this:
lst = [7, 4]
print(sum(lst)) # output is 11
print(sorted(lst)) # output is [4, 7]
If this is not what you have expected, you should rework your question and provide us with data samples for input and output.
+ 2
I have list=[“12”,”33”,”5”] i want sum it
+ 1
Please show us your try. In the meantime, here are some hints:
📍sum() is a built-in function that finds the sum of a list. It takes one parameter, the list.
📍sorted() is another built-in function, and it sorts a list. Once again, the only parameter is the list.
Try joining the lists together, and make use of these functions.