-4
def validar(pergunta, min, max):
x = int(input(pergunta))
while((x < min) or (x > max)):
print('Código Inválido')
print('Digite um número inteiro entre 10000 e 30000')
x = int(input(pergunta))
return x
def calcular(num):
print('Dígito |', end='')
pos = 0
while pos < 5:
for i in range(0, int(num[pos])):
print(f'{i} |', end='')
pos += 1
print()
print('Peso |', end='')
for peso in range(2, 7):
print(f'{peso:^5} |', end='')
print()
print('Multiplicação |', end='')
soma = 0
peso1 = 2
resto = 0
for d in range(0, 5):
for digito in num:
resultado = int(digito[d]) * peso1
soma += resultado
peso1 += 1
resto = soma % 7
print(f'{resultado:^5} |', end='')
print(f' Soma todos = {soma}')
print('-' * 75)
print(f' Resto de {soma} por 7 = {resto}')
print('-' * 75)
print(f'{int(num[0])} - {resto}')
print('------')
return f'{num}-{resto}'
digito = validar('Digite o código do produto: ', 10000, 30000)
calcular(digito)
Please explain exactly what your question is and how we can help you. Don’t just play the code in a question.
– Lucas Módolo
To know better how to ask a question, click here.
– Lucas Módolo
I voted to close as needing more details, but I was wrong. The correct closing vote is due to quality. In function
validar()
the return is always a wholex = int(input(pergunta))
which implies that on the linefor i in range(0, int(num[pos])):
an error will always be generated becausenum
is the return ofvalidar()
and being a whole cannot be slicednum[pos]
. The problem can be easily detected doing the code debugging.– Augusto Vasques
Not sure what you want to do, but looking at your code I think you’re trying to do this https://ideone.com/Nnt81K
– Augusto Vasques