- My Forums
- Tiger Rant
- LSU Recruiting
- SEC Rant
- Saints Talk
- Pelicans Talk
- More Sports Board
- Fantasy Sports
- Golf Board
- Soccer Board
- O-T Lounge
- Tech Board
- Home/Garden Board
- Outdoor Board
- Health/Fitness Board
- Movie/TV Board
- Book Board
- Music Board
- Political Talk
- Money Talk
- Fark Board
- Gaming Board
- Travel Board
- Food/Drink Board
- Ticket Exchange
- TD Help Board
Customize My Forums- View All Forums
- Show Left Links
- Topic Sort Options
- Trending Topics
- Recent Topics
- Active Topics
Started By
Message
Trouble with Loops in Python
Posted on 6/30/23 at 4:39 pm
Posted on 6/30/23 at 4:39 pm
I'm reading Automate the Boring Stuff with Python, and everything was going well until I ran into control flow, specifically 'where loops'.
I'm not sure if it's just the time of day or if this stuff is actually difficult to wrap my head around...
Any helps or advice is appreciated
Edit: I meant to say while loop.
I'm not sure if it's just the time of day or if this stuff is actually difficult to wrap my head around...
Any helps or advice is appreciated

Edit: I meant to say while loop.
This post was edited on 6/30/23 at 5:17 pm
Posted on 6/30/23 at 5:14 pm to bayoubengals88
you mean while loops?
wait til you find out about recursion lol.
wait til you find out about recursion lol.
This post was edited on 6/30/23 at 5:16 pm
Posted on 6/30/23 at 5:16 pm to Fat Batman

Yes, while!
Posted on 6/30/23 at 5:19 pm to bayoubengals88
may want to step back and explore if/else, booleans and truthy/falsey values in python. then im sure there is a decent video on youtube that breaks down while loops in python's syntax.
Posted on 6/30/23 at 6:10 pm to bayoubengals88
What's your issue? Just the flow or the conditional?
Posted on 6/30/23 at 6:49 pm to UltimaParadox
If you give me an example of a simple while loop, I’ll let you know.
Posted on 6/30/23 at 7:15 pm to bayoubengals88
count = 0
while count < 10
print("LSU won a baseball natty!")
count = count + 1
This would print that statement 10 times (0 - 9). The loop would stop once you hit iteration 11 (count would be the number 10) because the conditional (count < 10) is then false.
I tend to use for loops
while count < 10
print("LSU won a baseball natty!")
count = count + 1
This would print that statement 10 times (0 - 9). The loop would stop once you hit iteration 11 (count would be the number 10) because the conditional (count < 10) is then false.
I tend to use for loops
This post was edited on 6/30/23 at 7:59 pm
Posted on 7/1/23 at 12:56 am to bayoubengals88
Is the number even or odd, with the option to test another number or exit.
Or an alternative way to do the last if condition
quote:
continue = True
while continue:
....value = int(input("Enter a number: ")
....if value % 2 == 0:
........print(f"{value} is even")
....else:
........print(f"{value} is odd")
....user_response = input("Would you like to test another number? y/n ")
....if user_response == "n":
........continue = False
........print("Exiting...")
Or an alternative way to do the last if condition
quote:
....if user_response == "n":
........print("Exiting...")
........break
Posted on 7/1/23 at 7:34 am to bayoubengals88
There are better ways to learn Python. I suggest you put down that book and pick up this class CS50s Introduction to Programming with Python.
Posted on 7/1/23 at 11:17 am to TAMU-93
Thanks, I'm going to take a step back and just start CS50 from Harvard. Get a foundation from C first and then tackle Python.
Indecisiveness and ignorance has been the theme for me over the past few months as I've taken interest in Data Science and then Computer Science for the first time.
There's just so much out there.
Indecisiveness and ignorance has been the theme for me over the past few months as I've taken interest in Data Science and then Computer Science for the first time.
There's just so much out there.
This post was edited on 7/2/23 at 4:48 pm
Posted on 7/1/23 at 11:35 am to bayoubengals88
As someone who comes from a c background... I hate python
Posted on 7/1/23 at 12:42 pm to UltimaParadox
I never have to use while loops, just for loops for now. I guess while loops would be useful for interactive prompts where it needs to keep checking if a condition is True.
Posted on 7/1/23 at 3:44 pm to alabamabuckeye
While loops are a fundamental building block in basically all programming language. So if you keep solving then you will need them.
Generally you are correct keep looping until some condition is true. Granted it gets more complicated down the road. And also you usually don't want a while loop running wide open checking for a condition due to performance reasons, but that can be language dependent
Generally you are correct keep looping until some condition is true. Granted it gets more complicated down the road. And also you usually don't want a while loop running wide open checking for a condition due to performance reasons, but that can be language dependent
Posted on 7/1/23 at 10:28 pm to bayoubengals88
[ duplicate ]
This post was edited on 7/1/23 at 10:32 pm
Posted on 7/1/23 at 10:30 pm to bayoubengals88
quote:I'm a big fan of OCW from MIT. This looks like it might be a good starting point for you:
Data Science and then Computer Science for the first time.
Introductory Programming
I think 6.0001 is a much better option than Harvard's CS50.
ETA: most OCW lectures and recitation sections are on YouTube, FWIW.
This post was edited on 7/1/23 at 10:36 pm
Posted on 7/2/23 at 12:37 pm to tokenBoiler
Why are MIT lectures better than Harvard?
Posted on 7/2/23 at 11:40 pm to bayoubengals88
quote:Part of my job involves bringing new users up to speed with scientific computing. I've gone through 4 or 5 online courses in Python and R (topics I'm already familiar with) just to help me figure out effective ways to teach beginners.
Why are MIT lectures better than Harvard?
When I went through the CS50 set, it covered (IMO) too many topics superficially -- it went through several different languages. The MIT course sticks with Python, and uses it to introduce fundamental CS topics, and programming idioms that are language-agnostic.
I think sticking with one language for that is easier to get into and retain for the online students. CS50 just seemed too scatter-shot for me.
That was a few years ago; I haven't looked at it recently.
CS50 seemed to me to be a class for someone who has to take what might be their only computer course; 6.0001 seemed to be a class for people who wanted to start learning CS with no prior experience.
This post was edited on 7/3/23 at 4:08 pm
Posted on 7/3/23 at 8:46 am to tokenBoiler
That’s excellent. Thank you for a truly authoritative stance on the matter.
Posted on 7/3/23 at 9:21 am to tokenBoiler
I took CS 1301 (Intro to Python) from Georgia Tech before starting my Masters and found it pretty useful too FWIW
Popular
Back to top
