[Tutor] Why do I not get the same results for these two functions when I pass 7 as an argument?

Kengesbayev, Askar askar.kengesbayev at etrade.com
Fri May 3 16:48:36 CEST 2013


You need to change the condition statement:

  if days >= 3 < 7:  to  this    if days >= 3 and days < 7:

When it goes through the function it sees this statement days >= 3 as true and execute - payment -20.

Askar

From: Nonso Ibenegbu [mailto:jollynony at gmail.com]
Sent: Friday, May 03, 2013 2:10 AM
To: Tutor at python.org
Subject: [Tutor] Why do I not get the same results for these two functions when I pass 7 as an argument?

Hello everyone,
Wonder if someone can help me understand why these two codes do not give the same results for what looks essentially the same ("?") code. The argument passed is
7.

def rental_car_cost(days):
    payment = days * 40
    if days >= 7:
        return payment - 50
    elif days >= 3 < 7:
        return payment - 20
    else:
        return payment

and...

def rental_car_cost(days):
    payment = days * 40
    if days >= 3 < 7:
        return payment - 20
    elif days >= 7:
        return payment - 50
    else:
        return payment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130503/1f0211e6/attachment.html>


More information about the Tutor mailing list