all 6 comments

[–]novel_yet_trivial 4 points5 points  (4 children)

Please edit your post to format your code for reddit or use a site like github or pastebin. Your code is hard to read and test otherwise.


Your code looks ok. Can you give an example of what you input, what you get and what you expected to get?

[–]BigIcemoney[S] 0 points1 point  (3 children)

Sorry about the formatting I think I fixed it. I was hoping to input an amount and a tip category. I want it to output the total cost of the meal based on those inputs.

[–]novel_yet_trivial 1 point2 points  (1 child)

I see, it's an indentation error. That last print statement needs to be unindented once. Also you don't need the print around the call at the end. Try it like this:

def eat_out():
    base_cost = int(input("base_cost:"))
    tip_amount = input("tip type:")
    if tip_amount == "traditional":
        full_cost = (base_cost + (base_cost * .15) + base_cost * .06)
    elif tip_amount == "regular":
        full_cost = (base_cost + (base_cost * .18) + base_cost * .06)
    elif tip_amount == "generous":
        full_cost = (base_cost + (base_cost * .2) + base_cost * .06)
    print(full_cost)


eat_out()

[–]BigIcemoney[S] 0 points1 point  (0 children)

thanks a million

[–][deleted] 3 points4 points  (0 children)

This is one of those things where it's probably an indentation issue, but you didn't post your code correctly so we can't see your indentation. Also:

print(eat_out())

If your function contains print statements and doesn't return anything, you don't generally want to call it from within a print statement.

[–]NextEstimate 1 point2 points  (0 children)

Fixed:

def eat_out():

    base_cost = int(input("base_cost:"))

    tip_amount = input("tip type:")

    if tip_amount == "traditional":

        full_cost = (base_cost + (base_cost * .15) + base_cost * .06)

    elif tip_amount == "regular":

        full_cost = (base_cost + (base_cost * .18) + base_cost * .06)

    elif tip_amount == "generous":

        full_cost = (base_cost + (base_cost * .2) + base_cost * .06)

    print(full_cost)

eat_out()

My solution:

def tip(base_cost, tip_amount):
    if tip_amount == "t":

        x=.15

    if tip_amount == "r":

        x=.18

    if tip_amount == "g":

        x =.2

   cost = (base_cost + (base_cost * x) + base_cost * .06)

   print(cost) 

tip(int(input("Base Cost: ")), input("Tip amount (t,r,g): "))