Whenever I type "m" to try and get it to switch to the m block it just goes with days anyway. I'm doing this for my coding class and I KNOW that a lot of this is probably really repetitive code but this is my main issue. I am trying to get it to where if I type "d" or "D" it goes to the day block and if I type "m" or "M" then it goes with months. Please help
#π My If-else statement ignores my input
33 messages Β· Page 1 of 1 (latest)
@olive pollen
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
!or
The or-gotcha
When checking if something is equal to one thing or another, you might think that this is possible:
# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
print("That's a weird favorite fruit to have.")
While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.
So, if you want to check if something is equal to one thing or another, there are two common ways:
# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
print("That's a weird favorite fruit to have.")
# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
print("That's a weird favorite fruit to have.")
You can just do input(...) instead of (input(...))
I assume you were probably casting that input to something and forgot to remove the parens
Although instead of payment == "d" or payment=="D"
You can use
If payment.lower() == "d"
And using the same text in the input prompt as the print statement after it, seems redundant.
I know that I just don't know any other way
Just remove the print statement that repeats the prompt
Professor wants me to print the question and the input next to that but i also want the question to appear for the input up top
The question should appear when you call input()
Then the user types the answer on the same line and hits enter
What would a line like that look like?
Getting input with a prompt message? You already have it on line 3
Also you already are getting the payment period using a input prompt
Yeah you can do that with x = float(input("enter float: ")
whats your output?
That should show in the console as enter float: 6
>>> loan_amount = float(input("What is the loan amount? "))
What is the loan amount? 350.00
See, no need for an extra print 
should be
if repayment_period == "d" or repayment_period == "D":```
I would just do
if repayment_period in ["d", "D"]:
or make the input .lower() seems the most logical
although you could also just do
if repayment_period.casefold() == "d":
If you're comparing, you should use casefold. lower should be used for when you need to display lowercase.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.