0
Assertions Python
My basic calculator project I'm doing to practice python is fine but i've added some assertions to the Multiply function and when trying to make an assertion error occur I can't.. What's wrong with my assertions. (Trying to show the second argument in the output if the first argument occurs) https://code.sololearn.com/cMwYU4G32wZe/?ref=app
3 ответов
+ 2
The problem is that you are never reaching the multiply part.
Your code is only handling quit and add part.
In python every non empty string is evaluated as True in a conditional statement (if,elif)
user_input == "add" or "+" or "Add":
Now imagine user input is "*":
user_input == "add" is False.
But "+" is TRUE because it's a non empty string and we run the add code even when user input is * !!!
You should read that condition like this:
If user_input == "add" is True or
"+" is True or "Add" is True:
# do stuff
Your conditions(all) should be something like this:
if user_input == "add" or user_input=="+" or user_input=="Add"
- 2
bleh
- 3
tolong aku dulu..... apa ni moonton