Jump to content

Python Help

namarino

Hey guy, I have to write a function that takes in a list of numbers and then returns a series of symbols that correspond to the numbers. So if you got [1, 2, 3, 4] you would return:

o

oo

ooo

oooo

The problem that I'm running into is that in order to make them each on their own line, I have to add \n at the end of each string addition. But the last addition can't have a \n at the end of it. So this is my code so far.

def histogram(xs):	symbol = 'o'	string = ''		for index in xs:		string += (symbol * index) + '\n'		return string

The test cases given to us are really specific so this. So mine looks like this:

o\n

oo\n

ooo\n

oooo\n

 

instead of this:

o\n

oo\n

ooo\n

oooo

 

So how can I do this?? Sorry if this was a bit confusing...

 

 

EDIT: I figured it out...

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×