0

I created this program and I need it to output like this:
this

How can I do that?

n=int(input(""))
L = []
x=0
c=0
while x<=n-1:
    Numero=int(input(""))
    final="*"*Numero,Numero
    L.append(final)
    x=x+1
for elem in L:
        print(elem)
1
  • TypeError: sequence item 1: expected str instance, int found. How to convert from int to str. Thanks for your help! Commented May 22, 2017 at 1:42

3 Answers 3

3

elem is a tuple of a string and an integer number. There are several ways to display it as a string:

print(*elem)

print("%s %d" % elem)

print("{} {}".format(*elem))

print(elem[0], elem[1])
Sign up to request clarification or add additional context in comments.

2 Comments

One final question why i get None in the last line of the output? pastebin.com/f8uwqMe2
Because your function does not have a return and implicitly returns a None.
0

You can use format() to append strings:

n=int(input("Please input number"))
r=["*"*int(input("")) for i in range(n)]
for i in r:
    print("{} {}".format(i,len(i)))

Output:

Please input number4
4
2
3
1
**** 4
** 2
*** 3
* 1

Comments

0

You want to unpack the arguments to the function using *. So your print statement would become:

print(*elem)

See the python tutorial for more information.

>>> e = ('****', 4)
>>>> print(e)
('****', 4)
>>> print(*e)
**** 4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.