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.
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 :
- 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.
- Besides the phrase "take one down," you may not type in any numbers/names of numbers directly into your song lyrics.
- Remember, when you reach 1 bottle left, the word "bottles" becomes singular.
- 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 :)
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...