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 trial
Andrew Reidlinger
1,669 PointsCan't figure this objective out
Write a function named printer. The function should take a single argument, count, and should print "Hi " as many times as the count argument. Remember, you can multiply a string by an integer.
I've tried for 2 hours several different snippets of code that have made perfect sense to me that should achieve exactly what this is asking but nothing has worked so far.
Andrew Reidlinger
1,669 Pointsdef printer(int(count))
print("Hi " * int(count))
This was the last one I tried
Manish Giri
16,266 Pointscount is already a number, you don't need to cast it with int(count).
Andrew Reidlinger
1,669 PointsThat's what I originally assumed, so I was trying things like this and these weren't working either.
def printer(count)
print("Hi " * count)
Manish Giri
16,266 PointsAre you sure they want a space after "Hi"?
Andrew Reidlinger
1,669 PointsYes, and I've tried it with and without the space. I copied and pasted the task in my original post and I'm not seeing what I'm not doing correctly lol
Manish Giri
16,266 PointsI just tried the challenge, and this worked for me -
def printer(count):
print("Hi " * count)
Andrew Reidlinger
1,669 PointsI literally was just forgetting the colon lol I probably wouldn't have even noticed it if you didn't post that, thanks
Abubakar Gataev
2,226 PointsIt should be:
def printer(count): print("Hi " * count)
ps: print... is on the next line. It works!!
1 Answer
Manish Giri
16,266 PointsYour function should look like this -
def printer(count):
# your code here
Inside the function, you need to print "Hi" as many times as the number count is. For example, if count is 3, you'll print "HiHiHi".
And lastly, you can multiply a string by a number in Python, to achieve this.
Give it a shot!
Greg Kaleka
39,021 PointsThis is a better answer
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsHi Andrew,
Please show us your code! We can't tell you what you're doing wrong if you don't tell us what you're doing
It's best to input your code surrounded by back-tics (on the ~ key, typically), and with the language. Like this:
```python
[code goes here]
```
That'll give you some nice syntax highlighting.