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 Python Basics (2015) Logic in Python Print "hi"

Denis Ts
Denis Ts
2,751 Points

Hi , Please advise The challenge is to print "Hi" ( x times) as amount of function argument. in shell it works fine.

i have tried also to convert the argument to "int" ( just in case ) (also works fine in shell)

def printer(count): a = int(count) print ("hi ") * a

printer(5)

But still getting the same Can someone please suggest what's wrong here ?

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

printer(5)

2 Answers

James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points
def printer(count):
    print("Hi" * count)

in your code you also have "Hi " which will come out like Hi Hi Hi Hi Hi, not HiHiHiHiHi, but that may be what is needed in the challenge I cant remember

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Denis.

You've almost got it, but there are just a couple of small things.

  1. The count variable needs to be included inside of the parenthesis for the print statement.
  2. The challenge didn't ask you to call the function... just write it.
def printer(count):
    print("Hi " * count)

Keep Coding! :) :dizzy: