Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Day 1 of learning, seemingly simple program but struggling? Please advise on code so far.
Post Body

Hello

I am trying to complete the easiest challenge in a resource of programming challenges I found in a comment on this subreddit ( https://docs.google.com/document/d/1TyqD2_oDtiQIh_Y55J5RfeA91JJECc97xYIKM112H9I/edit )

The challenge is to print the entire lyrics of the song "99 bottles of beer on the wall" with the stipulations :

  1. If you are going to use a list for all of the numbers, do not manually type them all in. Instead, use a built in function.
  2. Besides the phrase "take one down," you may not type in any numbers/names of numbers directly into your song lyrics.
  3. Remember, when you reach 1 bottle left, the word "bottles" becomes singular.
  4. Put a blank line between each verse of the song.

so far this is what I have come up with. Please let me know if I am going in the right direction? I currently get an invalid syntax error on line 4 bottles:

for i in range(0,99):
    bottles = 99
    print((str(bottles)   ' bottles of beer on the wall, '   (str(bottles)   ' bottles of                 
beer. Take one down, pass itaround. ')
    bottles = bottles - 1
    print((str(bottles)   ' of beer on the wall.')

My initial thought was bottles in line 4 was invalid because I defined it outside of the for loop, but then I created it as a variable inside the loop instead. Is that an example of global variables or does that only apply to functions?

Sorry if I am way off base, it is day 1 of learning and it all seems pretty daunting.

Thank you

EDIT: For some reason I cant indent on reddit? However, I do have an indent starting on line 2

EDIT 2: I got it! Here is what I ended up with:

for bottles in range(99,0,-1):
    if bottles == 1:
        break
    print(str(bottles)   ' bottles of beer on the wall, '   str(bottles)   ' bottles of beer. Take one down, pass it around.')
    print(str(bottles)   ' bottles of beer on the wall.')
print(str(bottles)   ' bottle of beer! Take it down, pass it around. No bottles of beer on the wall!')

/u/crashfrog's comment about how for loops can increase / decrease by a set counter and the parenthesis really helped.

This feels great, it was my first attempt at something outside of the guided tutorials/lessons that I used all last night. Thank you all very much :)

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
11,540
Link Karma
432
Comment Karma
11,084
Profile updated: 3 days ago
Posts updated: 2 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago