Looking for practice while loop questions
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.comBest way to learn loops in python & make it stick?
For loops and while loops
I get what you are saying :) I need a lot of practice for stuff to stick. When I was learning conditionals and looping, the best advice I got was to start with some practice problems, then make up similar problems with my own data and scenarios. For example, you could write a program to loop through a list of addresses and have it return some information about each entry. Or, you could write a program to take keyboard input and keep printing some result until you enter 'N' (the while loop in action). We were also told to try to solve the problems without using while or for loops to help motivate why you would want them in the first place. That really helped solidify the concepts for me, because you can write code without the loops, but it gets long and tedious... Btw, another link I used was https://www.practicepython.org/.
More on reddit.comWhat is a for loop in Python?
How do I use a for loop in Python?
Can I use a for loop with a dictionary in Python?
Videos
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.