Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPaul Webb
Front End Web Development Techdegree Student 453 Pointsim stuck, i just cant figure out how to make it print hi as many times as count
i get that you can multiply an int and string, but that just uses a specific number. anyone?
def printer(count):
if count >= 1:
return True
else:
return False
if True:
print ('hi')
printer('count')
2 Answers
Gabbie Metheny
33,778 PointsIn this function, count
is just the name you're giving the argument that will be passed in. You can assume the argument will be an integer, so count
is just standing in the integer's place for now.
printer(4) # should give output: hihihihi
print('hi' * 4) # output: hihihihi
Let me know if it still isn't making sense, but you should be able to accomplish it in two lines of code total!
Paul Webb
Front End Web Development Techdegree Student 453 PointsHey thanks for your help. its making a bit more sense now. one more question though, i passed the coding challenge but i only when i changed print('Hi ' *4) to be print('Hi ' *5)
i'm trying to understand why, as i was supposed to make it print the same amount of hi's as there was in the count. thanks
def printer(count)
print('Hi ' *4)
printer(4)
Gabbie Metheny
33,778 Pointsprint('hi' *4)
was just the example I used to show you what your code should accomplish, the actual function should look like this:
def printer(count):
print('hi' * count)
Then Treehouse checks your code by passing in arguments to your function:
print(4)
# output: hihihihi
print(5)
# output: hihihihihi
Functions are reusable chunks of code, that's why you put in a variable name to stand in for the argument until someone actually calls the function. The challenge should've only let you pass if you wrote your code with the count
variable, not a number. The only thing I can think of is that when Treehouse tested your function, they tried to pass in 5 as an argument, so print('Hi' * 5)
still gave them what they were looking for. Let me know if that doesn't make sense!