In: Computer Science
IN PYTHON
Given a number of petals, print a string which repeats the phrases "Loves me" and "Loves me not" for every alternating petal. The last phrase printed (for the last petal picked) should be in all caps. Remember to include a comma and space between phrases, as shown in examples below.
Sample Input 1
3
Sample Output 1
"Loves me, Loves me not, LOVES ME"
Sample Input 2
1
Sample Output 2
"LOVES ME"
Python code:
#accepting number of petals
n=int(input())
#looping till the last petal
for i in range(n-1):
#checking if it is an alternating petal
if(i%2==0):
#printing Loves
me,
print("Loves me,
",end="")
else:
#printing Loves me
not,
print("Loves me not,
",end="")
#printing LOVES ME for last petal
print("LOVES ME")
Screenshot:
Input and Output: