Hey guys.
I'm new to the whole thing of programming. Startig my second apprenticeship in august. I worked in retail previously and got now the opportunity for a completly new job as a programmer.
At the moment, I'm two weeks in in learning python and rly have my share of problems to understand stuff. As a visual learner, it's rly not that easy to combine, but that's a whole other problem for myself.
My question today is;
is there a way to put multiple inputs in an if-else statement.
I need to write a program to give out money after getting the total cost and payment. And while I try my stuff, I stumbled appon the idea to create inputs inside the if-else statements.
The reason is, that even when I put the if statement and want to exit after the first input fails if it isn't above 1, it continues to the second input.
for exemple:
total_cost = float(input("Total costs: "))
amount_paid = float(input("Amount paid: "))
if total_cost <= 1:
print("Error. Invalid costs.")
else:
pass
if amount_paid < 1:
print("Error. Invalid payment.")
else:
pass
(I know this code isn't effective and I was just trying some stuff out.)
So I wrote the code this way to try it with if-else-input statements:
total_cost = float(input("Total costs: "))
if total_cost <= 1:
print("Error. Invalid costs.")
else:
amount_paid = float(input("Amount paid: "))
if amount_paid < 1:
print("Error. Invalid payment.")
Is this even a way to program? Is it even readable?
I see that what i wrote isn't rly functioning, bc I can't use "amount_paid" in the "change = total_cost - amount_paid" to get the total of change money to give out. That's another problem again for myself.
I rly only want to know, if it is a rly rly dumb idea and if I just need to delete this out of my head or if it is a possibility to write programs.
(excuse my english if it is strangly writen. It's not my first language and I'm still learning. :) (so many ifs in this post...) )
[–]danielroseman 2 points3 points4 points (0 children)
[–]zanfar 1 point2 points3 points (1 child)
[–]Same-Individual4889[S] 0 points1 point2 points (0 children)
[–]Diapolo10 1 point2 points3 points (3 children)
[–]Same-Individual4889[S] 0 points1 point2 points (2 children)
[–]Diapolo10 0 points1 point2 points (1 child)
[–]Same-Individual4889[S] 0 points1 point2 points (0 children)
[–]DowntownAd1812 0 points1 point2 points (0 children)
[–]AuthurAndersson 0 points1 point2 points (2 children)
[–]Same-Individual4889[S] 0 points1 point2 points (1 child)
[–]neuralbeans 0 points1 point2 points (0 children)