0

How do you solve the python question on lists?

I'm currently taking "python for beginners" but I'm having trouble solving the finale problem on "Lists" which is titled "Sum of Consecutive Numbers" so if anyone can tell me how to solve it and how it works I'd love to hear it.

14th Jun 2022, 4:06 PM
James Castillo
James Castillo - avatar
2 Answers
+ 2
You need to create a variable to hold the total. Create that variable initially with 0 then use the 'for loop' and iterate over a 'range'. Inside the 'for loop' increment that total 'variable'. Looks at hint in the task (it is shown in yellow box).
14th Jun 2022, 4:44 PM
Sandeep
Sandeep - avatar
0
Suppose you have a list of invoices amounts and you wanted to sum them up and calculate the total amount... invoices_amounts = [20.99, 5, 7, 10.99] total_amount = 0 for amount in invoices_amounts: total_amount += amount print(total_amount)
14th Jun 2022, 10:30 PM
Alejandro M GonzĂĄlez
Alejandro M GonzĂĄlez - avatar