Using a for loop, ask the user for five numbers. Store those numbers in a list. Each time you add a new number to your list, print the list. (Your list will initially be empty.)
You should report the sum of the numbers in the list at the end.
An example run of your program might look like this:
Number: 3
[3]
Number: 6
[3, 6]
Number: 12
[3, 6, 12]
Number: 2
[3, 6, 12, 2]
Number: -5
[3, 6, 12, 2, -5]
Sum: 18
This is my code right now:
my_list = []
for i in range(5):
new_number = int(input("Number: "))
my_list.append(new_number)
print my_list
print "Sum: " + new_number*5
I almost have this code right. There's just one problem: I need to print the sum. Right now, it's an error because I have a str
and int
object on line 6 and I need that fixed.
This is the error that it gives:
Error: Line 6
TypeError: cannot concatenate 'str' and 'int' objects on line 6