简体   繁体   中英

How to print out a string of a '&', equal to the length of a list

I want to print out a list of the character '&' as many times as there are in a given number. So if the number is 10, I want the result to be '&&&&&&&&&&&'

What I have done is turned the int into a list so I can better visualize what I want to perform.

def print_list_&(size):
    """super serious docstring"""
    result_1 = 1
    result_2 = size + 1
    result = list(range(result_1, result_2))
    return result

I'm stuck on where I go from here. This is university work so I'm better off with a push in the right direction than a straight answer.

'&' * 10 will give you '&&&&&&&&&&' . Therefore it seems you just need '&' * size .

Python 2:

N = int(raw_input())
print '&' * N

Python 3:

N = int(input())
print ('&' * N)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM