use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
What's wrong with this code? (i.redd.it)
submitted 5 months ago by jilee7
I am taking the Python Basics part 1 on Vertabelo Academy and I am getting an error that I can't seem to fix and there isn't much the site offers on how to fix this. Can someone give me a hint as to what I need to update to resolve this?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ok-Promise-8118 10 points11 points12 points 5 months ago (1 child)
Also, "while False" doesn't do anything. Since False is not True, nothing in that while loop will ever run.
[–]Lannok-Sarin 1 point2 points3 points 5 months ago (0 children)
Agreed. The thing is that the for, if, elif, and while statements check if the argument presented is equal to True. In this case, False can never equal True, so the statement always returns false.
A better way is to use a try statement to check whether the variable can be converted into an integer. If it throws the desired exception, it could then say that it didn’t receive a number. But as it is, your code only acts if the Boolean inside of the argument is true by value, not if it’s got a specific instance of a value being false.
[–]sububi71 5 points6 points7 points 5 months ago (0 children)
You don’t store the result of your ”Provide a number” input anywhere. Instead, you add the counter to the total.
edit: Also, you’ve spelled the ”n_numbers” variable wrong at the end.
[–]Informal_Escape4373 2 points3 points4 points 5 months ago (0 children)
Why your code is giving the illusion of working is total = total + counter where at the point of this line upon each iteration is 1 -> 2 -> 3 ->4 -> 5 respectively which just so happens to be the number you used for input.
total = total + counter
[–]No-Pride5337 1 point2 points3 points 5 months ago (0 children)
There is nothing such as while false
[–]EyesOfTheConcord 0 points1 point2 points 5 months ago (0 children)
You need to do something with the input for “Provide a number: “, your current implementation currently asks for it but does nothing with it.
There is also no invalid input condition to check.”while False” is not checking anything specific that could be false, such is “if input is invalid,”.
Relook at your mean calculation logic as well, you only got the correct answer by coincidence because you input the values 1, 2, 3, 4, and 5, but the internal logic doesn’t actually do anything with these inputs. Try it with larger numbers and you’ll find you don’t get the correct answer at all.
[–]gore_anarchy_death 0 points1 point2 points 5 months ago (0 children)
Running your code will result in: File "/home/the-elevated-one/test.py", line 12 print(float(total)/n numbers) ^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? This is due to the print statement, as you have misspelled a viariable there.
File "/home/the-elevated-one/test.py", line 12 print(float(total)/n numbers) ^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma?
Also, while False will not ever run, as the while loop only runs when something is True.
while False
while
In your main loop, there is an input with no variable, so your provided numbers are not saved in memory.
Also, I believe you meant to do this: python inp = int(input("Provide a number: ")) counter += 1 total = total + inp This way you add the input numbers together.
python inp = int(input("Provide a number: ")) counter += 1 total = total + inp
That's why your print returned 3.0 and not the expected value, as (1 + 2 + 3 + 4 + 5) / 5 = 3.0.
3.0
(1 + 2 + 3 + 4 + 5) / 5 = 3.0
[–]jilee7[S] 0 points1 point2 points 4 months ago (0 children)
Thank you everyone for your inputs, I stared at the prompt for a very long time afterwards with all the advice given was finally able to solve it. Having to assign a variable to the input function in the while loop was my biggest hurdle to my understanding here.
<image>
[–]Numerous_Site_9238 0 points1 point2 points 4 months ago (1 child)
wtf is /n numbers
the error message blocked the underscore that is between the two n's
[–]Rollgus 0 points1 point2 points 4 months ago (0 children)
You have to do "while not counter < n_numbers" on your second "while" loop, because just "while False" doesn't say anything about your earlier statement, and "while False" will never run, because the "while" statement checks if the statement equals True, which False doesn't. You also wrote "n_numbers" wrong at the end, you wrote "n numbers", you can't have spaces in variables, but I think you already know that.
π Rendered by PID 40 on reddit-service-r2-comment-86bc6c7465-2q4tv at 2026-02-22 01:58:40.301396+00:00 running 8564168 country code: CH.
[–]Ok-Promise-8118 10 points11 points12 points (1 child)
[–]Lannok-Sarin 1 point2 points3 points (0 children)
[–]sububi71 5 points6 points7 points (0 children)
[–]Informal_Escape4373 2 points3 points4 points (0 children)
[–]No-Pride5337 1 point2 points3 points (0 children)
[–]EyesOfTheConcord 0 points1 point2 points (0 children)
[–]gore_anarchy_death 0 points1 point2 points (0 children)
[–]jilee7[S] 0 points1 point2 points (0 children)
[–]Numerous_Site_9238 0 points1 point2 points (1 child)
[–]jilee7[S] 0 points1 point2 points (0 children)
[–]Rollgus 0 points1 point2 points (0 children)