Python Forum
Writing a function that accepts two integer parameters (lines and cheers)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing a function that accepts two integer parameters (lines and cheers)
#1
I have to create a function named "cheerleader" that produces the following output using parameters:

cheerleader(4, 3)
output Go Team Go Team Go
Go Team Go Team Go
Go Team Go Team Go
Go Team Go Team Go

A "cheer" is an occurrence of the word "Go" in the output. Neighboring cheers are separated by the word "Team", so 1 cheer is printed as "Go", 2 cheers as "Go Team Go", 3 cheers are printed as "Go Team Go Team Go", and so on.

This is the code I have so far but I can't figure out how to get part of the print of "Go Team Go" to print separate depending on the chants:

def cheerleader(line, cheers):
for i in range(line, cheers):
print(" " * (i * 3 - 3), end="")
print("Go Team Go")
cheerleader(2, 3)
Reply
#2
When I hear about something being repeated some number of times, with something joining those items together, I immediately think of a list, and the str.join method. Here's the docs for that:
>>> help(str.join)
Help on method_descriptor:

join(...)
    S.join(iterable) -> str

    Return a string which is the concatenation of the strings in the
    iterable.  The separator between elements is S.
Here's an example usage:
>>> " Spam ".join(["Eggs", "Eggs", "Eggs"])
'Eggs Spam Eggs Spam Eggs'
Hopefully, this will help you continue on your adventure :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write a function with three parameters? MehmetAliKarabulut 3 2,777 Mar-04-2021, 05:23 PM
Last Post: buran
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,806 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  is writing a function a pythonic thing to do? Avivlevi815 1 2,118 Dec-03-2018, 06:10 PM
Last Post: Gribouillis
  Writing python function difficulty kirito85 5 3,277 Oct-28-2018, 07:34 AM
Last Post: buran
  writing a function for isogram Shazily 4 12,020 Feb-03-2017, 05:35 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020