Python Input 0 automatically

178 Views Asked by At

I have a variable equal to a input. I want to make the input function (when user presses Enter) to count it as 0.

This is my code:

n1 = input('Εισάγετε Λεφτά :')
n2 = input('Εισάγετε Πλυσίματα Μέσα - Έξω :')
n3 = input('Εισάγετε Πλυσίματα Μηχανών :')
n4 = input('Εισάγετε Πλυσίματα Εξωτερικά :')
n5 = input('Εισάγετε Τι Ποσό Πήρε ο Σπύρος :')
n6 = input('Εισάγετε Έλλειμμα :')
n7 = input('Εισαγετε Πρόσθετο  Ποσό :')
n8 = input('Εισάγετε Ψιλά :')
answer = (str(float(n1) + float(n5) - int(n2) * 10 - int(n3) * 8 - int(n4) * 7 + float(n6) -     float(n7) - float(n8)))
print (float(answer))
input('Press Enter To Exit')

Currently, when I just press Enter on any of the inputs, it returns the ValueError because it needs a float.

1

There are 1 best solutions below

0
On BEST ANSWER

I think this is what you are looking for:

n1 = raw_input('Εισάγετε Λεφτά :') or 0
n2 = raw_input('Εισάγετε Πλυσίματα Μέσα - Έξω :') or 0
n3 = raw_input('Εισάγετε Πλυσίματα Μηχανών :') or 0
n4 = raw_input('Εισάγετε Πλυσίματα Εξωτερικά :') or 0
n5 = raw_input('Εισάγετε Τι Ποσό Πήρε ο Σπύρος :') or 0
n6 = raw_input('Εισάγετε Έλλειμμα :') or 0
n7 = raw_input('Εισαγετε Πρόσθετο  Ποσό :') or 0
n8 = raw_input('Εισάγετε Ψιλά :') or 0
answer = (str(float(n1) + float(n5) - int(n2) * 10 - int(n3) * 8 - int(n4) * 7 + float(n6) - float(n7) - float(n8)))
print (float(answer))
input('Press Enter To Exit')

and this is in case you use python2. If you are running on python3 you can use input inplace of raw_input (as it is in your script)

What's the difference between raw_input() and input() in python3.x?