How do I solve this question?

Write a function called oi_mate that prints the string “Oi Mate!” to the terminal. Then, call this function repeatedly to print “Oi Mate!” to the terminal at least 10 times.

How do I do this?

Never mind I solved it, I wasn’t including the correct indentation:

def oi_mate():
     print('Oi Mate!' * 10)
oi_mate()

This code does not solve the exercise:

call this function repeatedly to print “Oi Mate!” to the terminal at least 10 times

You call oi_mate() once (not repeatedly). More likely what this exercise was hoping to accomplish was… Either to encourage you to use a for loop, or to precursor a lesson on for loops.

Option 1, the for loop:

def oi_mate():
  print('Oi Mate!')

for i in range(10):
  oi_mate()

Option 2, no for loop:

def oi_mate():
  print('Oi Mate!')

oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()
oi_mate()

So you’ve accomplished something similar to the program intent, but haven’t actually solved the exercise.

1 Like

oh right, tbh most of my google searches returned for loops but i hadn’t learned them yet