I want to queue numbers. Python 3.6

Asked

Viewed 78 times

0

I want to show the output of the data in queue form, for how many times the user wants.

def ex1():
    valo = int (input("Insira o numero"))
    for t in range (1,valo+1):
        print((int(valo))*1)
print (ex1())

Ex: times = 4

Saida:
4
44
444
4444

2 answers

0

Serves for numbers, characters and also strings:

>>> '4'*2
'44'
>>> '4'*10
'4444444444'
>>> 'a'*10
'aaaaaaaaaa'
>>> 'abc'*3
'abcabcabc'

In the case of your code it is not necessary to transform it into an integer that can use what was received by the function input().

0


In python, when a string * 1 number this indicates how many times you will repeat the string em questão, its function can be like this:

def ex1(): 
    valor = input("Insira o numero: ") 
    repeticoes = int(input("Insira quantas repeticoes deseja: "))
    for item in range(repeticoes + 1):
        print(valor * int(item))

Output example:

Enter the number: 4

Enter how many repetitions you want: 4

4 44 444 4444

  • Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.