Code review for: http://codereview.stackexchange.com/questions/113743/number-addition#113743
Why do you use the strings "True" and "False" here?
repeat = "True" numbers = [] print("Type 00 to end") space() while repeat == "True": addnumber = int(input("Add a number: ")) numbers.append(addnumber) tna += 1 if addnumber == 00: repeat = "False"
Use proper booleans instead:
repeat = True
numbers = []
print("Type 00 to end")
space()
while repeat:
addnumber = int(input("Add a number: "))
numbers.append(addnumber)
tna += 1
if addnumber == 00:
repeat = False
You know that 00 is the same as 0? The message to the user says to "Type 00 to end", but it will end if he types 0 too. As you can verify yourself in a Python interpreter:
>>> int('00')
0
So the message is misleading, the code comparing to 00
is strange, and should be fixed.
Instead of this line with its comment:
for i in range(tna): # tna = total numbers added
It would have been better to just spell it out, and use a variable name that is understandable without further explanation.
But in this particular example, you didn't need that variable at all,
you could iterate over the numbers
list directly:
for num in numbers:
print('{} + {} = '.format(num, previous))
previous += num
space()
print(previous)
space()
space()