0
I need to carry out this program:
Rewrite your payment program using Try and except for that the program treats non-numeric entries amicably by printing a message and exiting program. The following shows two program executions:
Digite as Horas: 20
Digite a Taxa: nove
Erro, por favor, informe entrada numérica
Digite as Horas: quarenta
Erro, por favor, informe entrada numérica
The my code is as follows:
numero_horas=input("Digite o numero de horas:")
valor_hora=input("Digite o valor hora:")
print("Erro, digite numeros")
valor_total=int(numero_horas*valor_hora)
print("Valor total", valor_total)
try:
valor=int(valor_total)
print("Valor de Pagamento é:", valor)
except:
print("Inicie programa novamente")
Only there’s this mistake :
valor_total=int(numero_horas*valor_hora)
TypeError: can't multiply sequence by non-int of type 'str'
how can I solve this problem?
You are multiplying two strings; you need to convert to int first.
– Woss
Possible duplicate of Accept only numerics in input
– Woss