+ 1
Why is this giving me an error? Please help! I'm a beginner!
7 Antworten
0
https://code.sololearn.com/cKgF5nh316zg/?ref=app
i got what i wanted to code. Fuck Yes!!!!
0
Don't use "a" in the for loop. Use a trash variable (_). The object in the loop must be iterable. Use range(x).
Don't reuse variables like that. Don't modify x.
for _ in range (x):
y = input ()
a += y
0
Explanation of the answer:
If you use a inside the loop and modify it, you may increase it or decrease it, doing the loop a different number of times than you intended.
The variable _ can be used for loops in which you don't need to count how many times you have looped.
In general don't use the same variables in the loop that you use to define it.
0
The range part i understand, but trash variable is still a doubt. please elaborate!
0
Trash variable means a variable you don't plan to use and doesn't matter what value it has. It's there just because the syntax requires it. In python it is usual to use the underscore _ because it is easily recognizable and cannot be confused with other variables
0
https://code.sololearn.com/cO22BOO6k0XR/?ref=app
I changed it as per your instruction, now it's printing 5,6,7,8,9. No matter what value i assign 'a' as. Please rewrite the code if it's not too much to ask.
I just want to define my function and add two numbers.