-2

I am going to try to explain this the best I can. I have a task to make a pay phone price calculator based on day, duration, and time call started. I did two of the if statements and realized whenever I put in my answers all it does is print the result off the most recent if statement and does not really listen to what I want it to do. It is a bit hard to explain so I will just put my code, my input, and my result.

Code:

day = str(input('Enter the day the call started at: '))
start_time = float(input('Enter the time the call started at (hhmm): '))
duration = float(input('Enter the duration of the call (in minutes):'))
cost = duration

    if (start_time >= 08.00 and start_time <= 18.00 and day == "Mon" or "Tue" or "Wed" or "Thr" or "Fri"):
        cost = duration * 0.40
    
    if (start_time < 08.00 and start_time > 18.00 and day == "Mon" or "Tue" or "Wed" or "Thr" or "Fri"):
        cost = duration * 0.25
    
    print('$' + str(cost))

My inputs:

1: Fri, 2350, 22.  2: Sund, 2350, 22.

My results:

1: $5.5.  2: $5.5.

As you can see it did not even do what is inside the print statement. It just gave me the result of the outcome of the previous if statement. I also tried removing the "and day ==" and what is after and all that did is make the first print statement work fine while the second does not work it just prints my original duration so I think I messed up bad.

Ethan
  • 876
  • 8
  • 18
  • 34
Chexz
  • 19
  • 5

1 Answers1

0

When you're trying to connect multiple conditions using logical operators you have to compare each string separately. I mean it needs to be like this

day == "Mon" or day == "Tue" or day == "Wed"

And so on...

Python learner
  • 1,159
  • 1
  • 8
  • 20
  • or if you have a lot you can store them in a tuple or list and just check your value is in it. Like `day in ("Mon", "Tue", "Wed", "Thu", "Fri")` – Chris Doyle Oct 24 '21 at 16:06