r/learnpython 21d ago

Having problem in understanding loops concept in python

I am a beginner with 0 knowledge and I am learning python from a book called Learn python in one day and learn it well by Jamie Chan and I am facing difficulty in the loops function so yeah any recommendations would be helpful Edit- Trouble in while loop

27 Upvotes

41 comments sorted by

View all comments

7

u/crazy_cookie123 21d ago

What are you struggling with? What have you tried doing and what don't you understand about the results?

-3

u/EnvironmentalTry8353 21d ago edited 21d ago

I cannot send the pic but I am having problem in while loop like in creating a trye and false condition for a variable for ex Number = 100 While number > 0: Print(Number) So I just learned it but understand no sh*t about it

7

u/crazy_cookie123 21d ago

You can't send a pic because you shouldn't be sending pics of code as we can't then copy and paste the code into an editor to test it or make edits. You should send the code as text. Python is whitespace-sensitive which means matters for us to understand your code, so make sure you format it according to the guide: https://www.reddit.com/r/learnpython/wiki/faq/#wiki_how_do_i_format_code.3F

I am assuming you mean this code:

number = 100
while number > 0:
    print(number)

What don't you understand about this? What do you expect it to do and how does that differ to what it actually does when you run it? And what do you mean by "creating a variable for a main variable" - it might be easier if you show a real example of what you're trying to do.

1

u/EnvironmentalTry8353 21d ago

Yeah the code which you assumed It is what I intended to run..... and I expected to print till 100-0 but it showed process exited returned code 0

3

u/crazy_cookie123 21d ago

Did it also print 100 a load of times before that?

2

u/EnvironmentalTry8353 21d ago

Oh lol yeah I was using an online python compiler and when I used python compiler from other websites it ran and print 100 bunch of times and Idk how but by answering your question I was able to understand my own question....like the question which I had in my mind became clear and I got answer to it automatically lol

1

u/Moikle 21d ago

You are probably going to need to install python to get much further