0
I need to assign each integer value within a list of at least 1 item and at most 10 items to a separate variable. Then decrease 1 of each item, add them and print the result. These numerical values will be obtained by a input
. For example:
#Se ela tiver 2 itens:
lista = input().split()
#convertendo para tipo inteiro:
def int_converter(list_x):
counter = 0
while 1 == 1:
list_x[counter] = int(list_x[counter])
if counter == (len(list_x) - 1):
return list_x
else:
counter += 1
continue
int_converter(lista)
#armazenando em variáveis:
a1, a2 = lista[0], lista[1]
#fazendo as operações que preciso e imprimindo o resultado:
resultado = (a1 - 1) + (a2 - 1)
print(resultado)
The problem is that I do not know how many numbers will be typed by the user, only that will be at least 1 and at 10. How do I do this without creating a condition for each case? I did this and the code became giant.
If there is a way to do this already with the lists, please let me know how.
Why do you need to do this? If you don’t know how many values will be entered, how will you know which variables will exist? You cannot use the list itself?
– Woss
Not because I’m gonna have to do operations with the elements on that list. I need to decrease 1 of each element of the list and add the result and then print on the screen. Continuing the example of 2 items: result : (a1 - 1) + (a2 - 2) print(result)
– Gustavo Matias
But you can do that with the list...
– Woss
@Andersoncarloswoss as?
– Gustavo Matias
It will be easier for you to ask the question exactly what you need to do. What you asked is looking like a XY problem
– Woss
@Andersoncarloswoss will edit now
– Gustavo Matias