Looking for practice while loop questions
If statements within a while loop (beginner question)
Beginner question about While Loops
Ideas for practicing for and while loops?
For: print out only even numbers between 1 and 100. Now do it without using an if statement.
While: Ask the user for a secret password. Keep going until they get it right. Now do the same without using an if statement.
These are probably the most basic ideas. Once you have them down, you can build on your knowledge.
More on reddit.comVideos
I'm doing a crash course on Python. I'm working on While Loops. I'm a complete beginner and only have 1 week of coding under my belt.
I have to write a simple code. This is the expected outcome. https://lecontent.sololearn.com/material-images/e011c8caf4984e3cb5fa84f88e8c7b67-timer.png
I input a number, and then it counts down from that number down to 0. Here is my code:
number = int(input())
while number > 0:
number = number - 1
print(number)However, I'm having trouble finding the solution because the countdown does not begin at the number that I put in. If I put in '3', the code starts to count down from 2. (2, 1, 0)
This results in an error for the test. The test wants it to start at 3, even when I type in 3.
How can I fix this? Thank you.
I'm looking for projects that can help me practice for and while loops:
So far, I have mastered if statements, operators, and all the simple stuff, however, I have been struggling with loops for some time. I figure some practice projects could help me get the hang of it.
For: print out only even numbers between 1 and 100. Now do it without using an if statement.
While: Ask the user for a secret password. Keep going until they get it right. Now do the same without using an if statement.
These are probably the most basic ideas. Once you have them down, you can build on your knowledge.
It's hard to imagine any kind of program that wouldn't contain a loop; it's a pretty essential concept in the programmer's toolkit.
So really any project will make you write for loops. (Don't worry about while, it's actually used quite a bit less in Python.)
But I think better than practice is understanding. If you understand what for does then the conditions under which you should use it are pretty obvious.