Off Topic > Off Topic
Programming Megathread
Metario:
protip: if you're ever planning to integrate javascript into a game don't use the v8 javascript engine
Foxscotch:
--- Quote from: Metario on December 03, 2016, 05:54:28 PM ---protip: if you're ever planning to integrate javascript into a game don't use the v8 javascript engine
--- End quote ---
why
RedGajin:
so im having some trouble with this basic program in python: the idea is that it will ask a user to enter in numbers, it will put those numbers in a list, and then it will use a loop to add up those numbers. what am i doing wrong here?
--- Code: ---def main():
keep_numbering = 'y'
numbers = []
while keep_numbering == 'y':
num = input("What was the sale for this day?: ")
numbers.append(num)
keep_numbering = input("Do you want to add another sale? (y/n): ")
for index.num in range(len(numbers)):
total = sum(numbers)
main()
--- End code ---
Pecon:
Disclaimer: I never learned python.
In your for loop at the end it looks like you're just reassigning the total variable for each iteration of the loop, which would not accomplish adding each value since the only result you'll get is from the last iteration of the loop.
RedGajin:
--- Quote from: Pecon on December 14, 2016, 10:00:25 PM ---Disclaimer: I never learned python.
In your for loop at the end it looks like you're just reassigning the total variable for each iteration of the loop, which would not accomplish adding each value since the only result you'll get is from the last iteration of the loop.
--- End quote ---
the issue seems to be with "index.num" tho, this is the error message i get:
--- Code: ---Traceback (most recent call last):
File "C:/Users/xx/Downloads/exam_prepare.py", line 33, in <module>
main()
File "C:/Users/xx/Downloads/exam_prepare.py", line 30, in main
for index.num in range(len(numbers)):
NameError: name 'index' is not defined
--- End code ---