Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Headfirst Python Exercise
#2
In this example, the for loop and range(99, 0, -1) tells the script how many times to loop through something whether it be a word, function, object, etc. beer_num could be an underscore, letter, or word. There are special characters than can not be used.
You can get the same effects with a while loop.

Both give same result
print('----- for loop -----')
for _ in range(10, 0, -1):
    print(_)
bottles = 10
print()
print('----- while loop -----')
while bottles > 0:
    print(bottles)
    bottles -= 1
Output:
----- for loop ----- 10 9 8 7 6 5 4 3 2 1 ----- while loop ----- 10 9 8 7 6 5 4 3 2 1
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Headfirst Python Exercise - by GeorgeSears - Jun-05-2022, 10:27 AM
RE: Headfirst Python Exercise - by menator01 - Jun-05-2022, 11:52 AM
RE: Headfirst Python Exercise - by jefsummers - Jun-05-2022, 12:07 PM
RE: Headfirst Python Exercise - by GeorgeSears - Jun-11-2022, 06:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong code in Python exercise MaartenRo 2 1,601 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  Python Exercise Doubt azure 4 2,783 Apr-21-2020, 01:15 PM
Last Post: azure
  New to python, having trouble with an exercise Salkay 3 2,243 Feb-18-2020, 01:42 AM
Last Post: Salkay
  Exercise 20, Learn Python 3 the Hard Way Dixon 6 6,156 Feb-26-2018, 04:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020