This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# These exercises correspond to the tutorial on https://www.anaisberck.be/python-loops/
### Exercise 1. Print a list of words of the song
# + next to each word its position in the sentence
# Prince, Purple Rain (using a hashtag = making a comment)
song="I never meant to cause you any sorrow\n\
I never meant to cause you any pain\n\
I only wanted to one time to see you laughing\n\
I only wanted to see you\n\
Laughing in the purple rain."
# each word has a unique number
pos=0
words=song.split()
forwordinwords:
print(word,pos)
pos+=1
# index of words, using string method index()
forwordinwords:
print(word,song.index(word))
### Exercise 2: rewrite song by copying words with r to the beginning of the song
words_with_r=[]
forwordinwords:
if'r'inword:
words_with_r.append(word)
new_text=words_with_r+words
print(''.join(new_text))
### Exercise 3: create an Anaerobe of the song (remove all r’s)