I am new to Python. It is my first programming language and I am having a hard time comprehending what people think is simple (it probably is). It's making me feel stupid to say the least. I could very much use some pointers with something I am stuck on. Essentially what I need to do is create a program which will create a text file containing the words of 10 green bottles.
def kevin():
file = open('greenbottles.txt','a')
file.write(a)
file.close()
def skinner():
kevin('rabbits\n')
skinner()
This is what I've done so far to create and write to a text file. (The file should appear in same directory as the Python file is located according to what I've seen and read. I've noticed sometimes it doesn't appear?) When I open the file it should have rabbits written in it and \n
means to force create a new line.
What I need to do is write the verses of the song in the text file using lists and variables. Also most of the song should be created in a loop (I thought a while loop would be best). I would be thankful if someone can give me some pointers on how to add a verse in.
"Ten green bottles
Hanging on the wall
Ten green bottles
Hanging on the wall
And if one green bottle
Should accidentally fall
There'll be nine green bottles
Hanging on the wall"
One of the verses.
What I am expecting is that this code should create a text file containing the words rabbit. The kevin
and skinner
is what I named the functions so I could understand it a little better; they can be called whatever you would like.