+ 2

AttributeError: 'tuple' object has no attribute 'append'

So i’ve learned the first 2 modules of python and i wanted to write a program where you could type some numbers and it would give you the average of them. I had an error “AttributeError: 'tuple' object has no attribute 'append'” at line 22 and i looked it up, because i couldn’t figuer out what i did wrong. I’ve learned that a tuple is like a list but you can’t add anything and that it doesn’t use square brackets and i do clearly in line 4, so I can’t figuer out what i did wrong. Could anyone explain my mistake? https://code.sololearn.com/cCF62uJ2VMs2/?ref=app

15th Jul 2018, 1:10 AM
Max Poppe
Max Poppe - avatar
12 Respuestas
+ 8
Max Poppe I haven't figured out the problems with your code, but I just wanted to thank/congratulate you for the quality of your question. It would be nice if everyone took the time to post thoughtful questions like that.
15th Jul 2018, 5:39 AM
David Ashton
David Ashton - avatar
+ 7
You have commas at the end of lines 1-4. 1: print("to stop adding numbers type 'quit' "), 2: input_user = input("type here your number:"), 3: result = 0, 4: input_numbers = [], I think Python automatically creates a tuple for lines 2 & 4 because without the parenthesis this is normally a multi-assignment syntax: a,b = b,a ...but without two variables on the left, Python took the 'safe' route, a tuple. Line 1 appears to be ignored like the second part is an empty line, and You overwrite line 3's result later, so it doesn't cause a problem.
15th Jul 2018, 3:23 AM
Kirk Schafer
Kirk Schafer - avatar
+ 7
The code that calculates your average is indented at the same/deeper level as an earlier always-'break'. This makes it unreachable code. (Hint)
15th Jul 2018, 4:22 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
Princetronixx wow i’m so embarassed right now. In my other code I did it right, well thank you so much for helping me. aparently I’ve also a mathematical mistake but at least I get a number now, I only devide the first number of the list, because i reset the sum every time, but i fixed it so thank you very much
22nd Jul 2018, 10:46 PM
Max Poppe
Max Poppe - avatar
+ 2
There's not a single mistake, but there are a number of mistakes, firstly if you want to take multiple input, you have to include it inside the loop or use split().Check my code: https://code.sololearn.com/cpChbcip2utc/?ref=app
15th Jul 2018, 5:24 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 2
David Ashton well thanks anyways for your effort and looking at my code.
15th Jul 2018, 12:03 PM
Max Poppe
Max Poppe - avatar
+ 2
How do you feel about functions? Like, do you have any practice with them, can you use them, do you have to stick with this format?
16th Jul 2018, 10:40 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Kirk Schafer thanks for the hint not that I really know what that means, but I will try. I know how to make a code that works but I’ve been trying to fix this one for too long just to give up so I’ll stick with the mechanism of this code.
16th Jul 2018, 10:11 PM
Max Poppe
Max Poppe - avatar
+ 1
Kirk Schafer i’m only at module 2 I’d love to learn more, but I’m to busy to add more things to my sheet where i write everything I’ve learned so I took a break until I can put it on there, but I haven’t learned about the function “def” ect so this it what I have to do it with. For someone who knows the entire language it would probably be easier, but i like challenges.
16th Jul 2018, 11:42 PM
Max Poppe
Max Poppe - avatar
+ 1
your code contains bugs and errors on lines 7: (bug), if the user inputs "quit" the program must calculate the average but the problem is you *Break* before the calculation that is why it always says average is zero 8 & 9 : (error) these lines are not correct the right way to call len is len(input_numbers) 11 :(error) the correct way to access members of a list is by using square brackects [ ] that is addition_number = input_numbers [index]
22nd Jul 2018, 8:36 AM
Princetronixx
Princetronixx - avatar
0
Kirk Schafer that could be, I honestly do not know, but without the comma’s i’ve another problem because I’ve used too much memory or time or something like that. so after trying out a bunch of things I tried a comma and my problem went away. On python itselve it sais that it can’t run multiple variables at a time with the error “SyntaxError: multiple statements found while compiling a single statement”
15th Jul 2018, 11:36 AM
Max Poppe
Max Poppe - avatar
0
Thank you for your help, I actually tried to put it in before, but I still had errors so I removed it back to it’s original spot (outside) the while statement. I’ll keep it in there and try to figuer out the last few bugs, because now it sais that my result is 0 instead of the average of my numbers.
15th Jul 2018, 11:58 AM
Max Poppe
Max Poppe - avatar