sillysausage
sillysausage

Reputation: 1

TypeError: '<=' not supported between instances of 'int' and 'function'

I've been working on this for a few days and got it 'kind of' working, but couldn't get the whole programme to function and every time I change something there's another error! I'd really appreciate your help on this one.

What I want to achieve:

Basically the driver needs to enter the distance, and whether there is surge pricing, and it needs to come back with a final fare.

Here's the code:

# The base fare for an Uber trip
base_fare = 2.50      

# Additional price for every mile, this will be multiplied by distance travelled
extra_fare = 1.25

surge_increase = (float(input("Please enter how much your current surge pricing is: ")))

# Find if there is any surge pricing going and how much it is
def surge_fare(distance_in_miles):
   total_surgefare = base_fare + (surge_increase * distance_in_miles)
   return total_surgefare()

# Creates a function that determines the total fare by adding the base fare to the extra fare according to how
# far has been travelled
def uber_fare(distance_in_miles):
   total_fare = base_fare + (extra_fare * distance_in_miles)
   return total_fare()

   
if total_surgefare <= str(0):
   while True:
       try:
           total_fare = uber_fare(float(input("Please enter how many miles you have driven on this ride: ")))
       except ValueError:
           print("That's not a number. Please enter how many miles you have driven on this ride. ")
       else:
           print("Your total fare is £%.2f" % total_fare)
           break

if total_surgefare > str(0):
   while True:
       try:
           total_surgefare = surge_fare(float(input("Please enter how many miles you have driven on this ride: ")))
       except ValueError:
           print("That's not a number. Please enter how many miles you have driven on this ride. ")
       else:
           print("Your total fare is £%.2f" % total_surgefare) 

The error I get is

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-82-6d5f49e9b1ab> in <module>
     19 
     20 
---> 21 if int(0) <= total_surgefare:
     22     while True:
     23         try:

TypeError: '<=' not supported between instances of 'int' and 'function'
I have tried lots of different approaches, maybe I'm using the wrong function even. I added int(0) thinking it would help, obvs not. It is not 100% complete as I want to fix this error before moving on.

Upvotes: 0

Views: 907

Answers (2)

Sardar Badar Saghir
Sardar Badar Saghir

Reputation: 65

The issue is that you did not define the total surge fare. Please Define the variable:

    # The base fare for an Uber trip
base_fare = 2.50

# Additional price for every mile, this will be multiplied by distance travelled
extra_fare = 1.25

surge_increase = (float(
    input("Please enter how much your current surge pricing is: ")))


# Find if there is any surge pricing going and how much it is
def surge_fare(distance_in_miles):
    total_surgefare = base_fare + (surge_increase * distance_in_miles)
    return total_surgefare


# Creates a function that determines the total fare by adding the base fare to the extra fare according to how
# far has been travelled
def uber_fare(distance_in_miles):
    total_fare = base_fare + (extra_fare * distance_in_miles)
    return total_fare

# ASSING VALUE TO total_surgefare according to your need
total_surgefare = surge_fare(float(input("Please enter how many miles you have driven on this ride: ")))
if total_surgefare <= 0:
    while True:
        try:
            total_fare = uber_fare(
                float(
                    input(
                        "Please enter how many miles you have driven on this ride: "
                    )))
        except ValueError:
            print(
                "That's not a number. Please enter how many miles you have driven on this ride. "
            )
        else:
            print("Your total fare is £%.2f" % total_fare)
            break

if total_surgefare > 0:
    while True:
        try:
            total_surgefare = surge_fare(
                float(
                    input(
                        "Please enter how many miles you have driven on this ride: "
                    )))
        except ValueError:
            print(
                "That's not a number. Please enter how many miles you have driven on this ride. "
            )
        else:
            print("Your total fare is £%.2f" % total_surgefare)

Assign total surge variable value according to your need. NOTE: I ADDED THE COMMENT " # ASSING VALUE TO total_surgefare according to your need" Assign the value to the variable below that comment

Upvotes: 0

Ayush
Ayush

Reputation: 21

While defining the surge_fare function you return total_surgefare() the parentheses at the end try to call it as a function so instead do return total_surgefare (similarly change the return total_fare() part in the uber_fare function)

Upvotes: 2

Related Questions