def change():
if choice == 1: #<--- issue here
while True:
amt = float(input("Enter amount of cash: $"))
if amt >= a:
print("Your change will be: ${:.2f}".format(amt - a))
break
else:
print("Not enough, missing: ${:.2f}".format(a - amt))
input("press enter to continue")
a = 15.60
b = 56.12
c = 89.53
d = 32.93
print("1. a: $15.60\t\t\t2. b: $56.12\n3. c: $89.53\t\t\t4. d: $32.93")
choice = input("Choose product (1-4): ")
change()
If I remove line 2, it would function properly but choice 1 would not be selected. I'd like it so this would run while choice 1 is selected. For some reason it's not allowing me to put an if statement before while loop. Is there a solution?
3 Réponses :
C'est le problème de votre déclaration d'entrée. Dans Python 3 Entrée, get défaut en tant que chaîne.so Vous devez le convertir en Entreger comme ci-dessous.
choice = int(input("Choose product (1-4): "))
Veuillez essayer ci-dessous le code
chaîne de moulage en entier dans Python 3.x Utilisez INT ()
choice = int(input("Choose product (1-4): "))
Dans Python 3.x,
entrée () code> produit des chaînes. Aucune chaîne n'est égale à1 code>. Vous devez soit appliquerint () code> à l'entrée, ou comparez-le contre"1" code>.Choice = Int (Entrée ("Choisissez le produit (1-4):")) code>.Ahh j'ai oublié! Merci les gars!
Le problème n'a rien à voir avec le
pendant la déclaration code>. Vous auriez le même problème avec une déclaration là-bas.