64.7k views
18 votes
Edhesive 7.2 code practice Write a function named ilovepython that prints out I love Python three times. Then, call that function.

User Gyuri
by
4.2k points

2 Answers

6 votes

Final answer:

The function named 'ilovepython' is defined using Python's 'def' keyword, and it prints 'I love Python' three times inside a loop. After defining the function, you call it by its name with parentheses to execute the print statements.

Step-by-step explanation:

Learning Python: Creating and Calling a Function:

To write a function that prints 'I love Python' three times, we define the function using the def keyword, followed by the function name ilovepython and a colon. Inside the function, we use a for loop or consecutive print statements to output the phrase three times. After defining the function, we call it by writing its name followed by parentheses.

Function Definition and Call

Here is an example of how the function can be defined and called:

def ilovepython():
for i in range(3):
print('I love Python')
ilovepython()

This example uses a for loop with the range function to repeat the print statement three times.

User RuuddR
by
4.0k points
2 votes

Answer:

def i_love_python():

for _ in range(3):

print("I love Python")

i_love_python()

Step-by-step explanation:

User Stijn Leenknegt
by
4.9k points