0
votes

i know this is a completely noob question, but how can i add the result from a input(), add it and print it? this is the code:

import time
#valores de definicao da cortina
cortinas_cm = 100
cortina_preco = 5

#nome e apelido
nome = input("1º Nome" "\n")
apelido = input("Apelido" "\n")

#teste de listagem de cliente
inventario = []
inventario.append(nome + " " + apelido)

#inputs de utilizador para calcular cortinas
quantidade_cm = input("Quantos cm pretende? em cm!" "\n")
inventario.append(quantidade_cm)
print("------------------\n")
print(inventario)
print("\n------------------\n")

#converter o input em string
quantidade = float(quantidade_cm)

#valor total com taxa de comerciante
preco = quantidade * cortina_preco * 1.05
print("preço total e: ")

#converte se em string para que se possa imprimir com texto depois
print (str(preco) + " eur!")

#print de restante de tecido
quantidade_restante = cortinas_cm - quantidade
print("quantidade restante: ")
print(str(quantidade_restante)+ " cm!")

#teste de if
tecla = input("Comprar mais: y or n? \n")

if tecla == "n":
    hora = time.strftime('%X %x %Z')
    print (hora)
else:
    mais_mais = input("Quanto mais deseja? \n")
    total_float = float(mais_mais)
    total_total = quantidade_restante + mais_mais
    print(total_total, total_float)

#loop teste
if  quantidade_restante <= 10:
    print("Quase no limite de stock")
else:
    print("Obrigado pela sua compra")

#para manter a janela aberta
input()

Every time i run the program when i enter in the "if" and add other value, it gives an error regarding cannot add str with float. I have already transformed the input() in float! Can you help me out?! The comments are in Portuguese, so any questions regarding any statement just ask!

1

1 Answers

0
votes

You assigned the conversion to float to the wrong name:

mais_mais = input("Quanto mais deseja? \n")
total_float = float(mais_mais)
total_total = quantidade_restante + mais_mais

mais_mais is still a string. Assign the conversion to mais_mais instead:

mais_mais = input("Quanto mais deseja? \n")
mais_mais = float(mais_mais)
total_total = quantidade_restante + mais_mais