-3

This is my code:

def totalPrice(meal, tip):
    meal = input("What was your total meal price?")
    tip = input("What would you like to tip?")

    total_bill = meal * (tip/100) + meal
    return total_bill

 print(totalPrice(meal,tip))

When I run it, nothing happens. I'm curious as to why my input is not printing in the console and where the error is happening.

gllk
  • 1
  • 1
    Your code has an Indentation Error. You need to post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so we can run your code – Tomerikoo Aug 12 '19 at 19:04
  • just the indentation error?! – Cryptoharf84 Aug 12 '19 at 19:05
  • Possible duplicate of [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – G. Anderson Aug 12 '19 at 19:06

4 Answers4

1

Because you divide a string. Convert the string to a float and remove the parameters if you don´t use it:

def totalPrice():
    meal = float(input("What was your total meal price?"))
    tip = float(input("What would you like to tip?"))

    total_bill = meal * (tip/100) + meal
    return total_bill

 print(totalPrice())

Or move the parameters out of your function:

def totalPrice(meal, tip): 
  total_bill = meal * (tip/100) + meal
  return total_bill

meal = float(input("What was your total meal price? "))
tip = float(input("What would you like to tip? "))
print(totalPrice(meal, tip))

Finally, everything works fine.

What was your total meal price? 1
What would you like to tip? 2
1.02
Kampi
  • 1,798
  • 18
  • 26
0

I think there are some code errors there. There is no need to receive the variables meal and tip on your function because you are creating them from an input in there. You also have to cast the input to float to be able to make the math. Try this:

def totalPrice():
    meal = float(input("What was your total meal price? "))
    tip = float(input("What would you like to tip? "))

    total_bill = meal * (tip/100) + meal
    return total_bill

print(totalPrice())
Jorge Morgado
  • 1,148
  • 7
  • 23
0

The problem was the input you were taking was of String type & Some indentation error was there

Syntax for int type is

variable_name=int(input(" "))

Try This

def totalPrice(meal, tip):
    total_bill = meal * (tip/100) + meal
    return total_bill

meal = int(input("What was your total meal price?"))
tip = int(input("What would you like to tip?"))
res=totalPrice(meal,tip)
print(res)
0

You can use this:

meal = int(input("What was your total meal price?"))
tip = int(input("What would you like to tip?"))
def totalPrice(meal, tip):
    total_bill = meal * (tip/100) + meal
    return total_bill
print (totalPrice(meal,tip))

or this:

def totalPrice():
    meal = int(input("What was your total meal price?"))
    tip = int(input("What would you like to tip?"))


    total_bill = meal * (tip/100) + meal
    return total_bill

print (totalPrice())
Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32
Mhmd Asaad
  • 104
  • 1
  • 3