Jump to content

problem defining function(python)


Recommended Posts

hello there

Im making a small thing that make the price of your car...

but there is no thing happened the python say there is no error

but I need a result  there is no resulet i def days by what you are writing (I know its simple cause i didnt add any if for check this cause i test my self...)

but the days cant transfer to cost why that happend ?

this is my code

	print "hello there"
print "but the days that you want to but your car there"
days = raw_input()
def rental_car_cost():
    cost = str(days) * 40
    if days >= 7:
        return cost - 50
    elif days >= 3:
        return cost - 20
	

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I not understand very well what  you want but that should be.

inputDay = raw_input("Put the days that you want to buy your car there: ")
def rental_car_cost():

    if inputDay.isdigit():
        cost = int(inputDay) * 40
    
        if inputDay >= 7:
            print cost - 50
        elif inputDay >= 3:
            print cost - 20
        else:
            print 0 # something else
    else:
        print "The data type must be numbers integers."
        
rental_car_cost()

Here you can test it:

https://goo.gl/GX6890

Spoiler

inputDay = raw_input("Put the days that you want to buy your car there: ")
def rental_car_cost():
    if inputDay.isdigit():
        cost = int(inputDay) * 40
        if inputDay >= 7:
            return cost - 50
        elif inputDay >= 3:
            return cost - 20
        else:
            return 0 # something else
    else:
        return 0
        
print rental_car_cost()

 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.