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

Python

Can'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.

Hi 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 :blush:

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.

def printer(int(count))
    print("Hi " * int(count))

This was the last one I tried

count is already a number, you don't need to cast it with int(count).

That's what I originally assumed, so I was trying things like this and these weren't working either.

def printer(count)
    print("Hi " * count)

Are you sure they want a space after "Hi"?

Yes, 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

I just tried the challenge, and this worked for me -

def printer(count):
    print("Hi " * count)

I literally was just forgetting the colon lol I probably wouldn't have even noticed it if you didn't post that, thanks

It should be:

def printer(count): print("Hi " * count)

ps: print... is on the next line. It works!!

1 Answer

Your 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!

This is a better answer :blush: