1
Summary of my program/ problem: I need to draw at an ATM between 10 and 600 reais. When running the program, any value above 100 it prints correctly, but if I put any value below 100 it presents the error described below.
I have the following error in my program:
Traceback (most recent call last):
File "f:/Formação Acadêmica/Tecnologia/Udemy/Python/estruturaDeDecisao.py", line 29, in <module>
intUnidade = int(unidade)
ValueError: invalid literal for int() with base 10: ''
The question asks the following:
Make a program for an ATM. The program should ask the user the value of the withdrawal and indicate how many notes of each value will be provided. The available banknotes will be 1, 5, 10, 50 and 100 reais. The minimum value is 10 real and the maximum 600 real. The program should not worry about the amount of banknotes on the machine. Example 1: To withdraw the amount of 256 reais, the program provides two notes of 100, a 50 banknote, a 5 banknote and a 1 banknote; Example 2: To withdraw the amount of 399 reais, the program provides three notes of 100, a 50 banknote, four 10 banknote, a 5 banknote and four 1 banknote.
The code I built in Python is following:
print(' ')
print('-------------------------------------------------------------------------------------')
print(' BEM VINDO AO CAIXA ELETRONICO ')
print('-------------------------------------------------------------------------------------')
print(' Informamos que o valor mínimo para saque é de R$ 10 reais e o máximo R$ 600 reais ')
print('-------------------------------------------------------------------------------------')
valorSaque = int(input(' Informe o valor de saque R$ '))
print('-------------------------------------------------------------------------------------')
saqueStr = str(valorSaque)
centena = saqueStr[0:1]
intCentena = int(centena)
dezena = saqueStr[1:2]
intDezena = int(dezena)
unidade = saqueStr[2:3]
intUnidade = int(unidade)
print('O saque terá as seguintes notas: ')
print(' {} nota(s) de R$ 100!'.format(intCentena))
if intDezena == 5:
print(' 1 nota de R$ 50')
elif intDezena > 5:
dezenas = intDezena - 5
print(' 1 nota de R$ 50')
print(' {} nota(s) de R$ 10'.format(dezenas))
elif intDezena > 0 and intDezena < 5:
print(' {} nota(s) de R$ 10'.format(intDezena))
else:
pass
if intUnidade == 5:
print(' 1 nota de R$ 5')
elif intUnidade > 5:
unidades = intUnidade -5
print(' 1 nota de R$ 5')
print(' {} nota(s) de R$ 1'.format(unidades))
elif intUnidade > 0 and intUnidade < 5:
print(' {} nota(s) de R$ 1'.format(intUnidade))
else:
pass
What should I do to get him to accept scores? Ex.: 55, 70, 25, 90 etc.
In your program you are assuming that the user will always type a number with hundred, ten and unit, the correct would be to do a check before "trying to separate the numbers this way". For when the number does not have three digits the error occurs.
– Danizavtz