Need help making an adding machine using Lists, Loops And Conditionals | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need help making an adding machine using Lists, Loops And Conditionals

Hello im pretty new to python and programming in general and I was wondering if I could get a bit of help with starting this program I have to do for my college class. In this Lab we have to create a program that stimulates an adding machine. It's suppose to read from a list and add them. I've been having a really hard time understanding and memorizing Lists, Loops and Conditionals which is why I need help starting this program out. If anyone is willing to reach out and guide me through it then it would be really helpful.

12th Feb 2021, 3:05 AM
Torm
Torm - avatar
5 Answers
+ 1
Summing up list elements using Python is straight forward, e.g my_list = [ 1, 2, 3, 4, 5 ] print( sum( my_list ) ) I understand the requirement to use list and loop, but I'm not understanding why you are required to use conditionals. Is there a specification about values worth to be included in the value summary? e.g. only positive numbers, odd/even numbers etc.
12th Feb 2021, 3:11 AM
Ipang
+ 1
Ok so for example this list [ 10, 20, 30, 0, 40, 50, 60 ] You are required to have [ 60, 150 ] In list <answer>, is that it?
12th Feb 2021, 4:02 AM
Ipang
+ 1
Yes that's it. Like the numbers I have for example [1, 5, 3, 0, 8, 2, -3, 8, 0, 10, 0, 5, 2, 0, 6, 2, 0] it should all come to an output of 15 10 9 8 7
12th Feb 2021, 5:28 AM
Torm
Torm - avatar
+ 1
Wait, how did those number come to be? I thought the task was to add the elements until there's a zero. [1, 5, 3, 0, 8, 2, -3, 8, 0, 10, 0, 5, 2, 0, 6, 2, 0] 1 + 5 + 3 => 9 8 + 2 + (-3) + 8 => 15 10 => 10 5 + 2 => 7 6 + 2 => 8 Did I miss something? or misunderstand?
12th Feb 2021, 9:12 AM
Ipang
0
In the instructions it also states that when it encounters a zero in the list it's suppose to put the current total into a separate list called answers and then reset the running total back to zero. So basically each team it hits 0 in the list it's suppose to add on the next numbers and so on.
12th Feb 2021, 3:55 AM
Torm
Torm - avatar