Jump to content

Don't know what's wrong with tip calculator. (Python)

I'm trying to make a scrip that asks for user input of the meal price and percentage tip they want to pay.

After inputting the tip percentage it just closes.

print "What is the cost of the meal including vat"
meal_plus_vat = int(raw_input())



print "Input percentage tip in decimal format"
tip = int(raw_input())


total_due = meal_plus_vat * tip

tip_amount = total_due - meal_plus_vat

print "Total due is" + str(total_due)

print "Tip is" + str(tip_amount)

time.sleep(10)

 

Link to post
Share on other sites

What is the issue you're encountering exactly ?

Is it python 2 or 3?

why don't you simply use the input function ?

AMD Ryzen R7 1700 (3.8ghz) w/ NH-D14, EVGA RTX 2080 XC (stock), 4*4GB DDR4 3000MT/s RAM, Gigabyte AB350-Gaming-3 MB, CX750M PSU, 1.5TB SDD + 7TB HDD, Phanteks enthoo pro case

Link to post
Share on other sites

I'm not a python guy, but if it's a script then it closes after the tip is input because there is nothing to stop the program from finishing other than the timer which, if its like C, is set to 10 milliseconds, so you'll never see the output as it flashes up too quickly. If you call the script from a console window that doesn't close after execution you would see the output. But I don't know what tools are used with python so don't know how they operate, just making assumptions and maybe not helping at all! 

Link to post
Share on other sites

I would also question how you plan to enter the tip. I would expect to enter 5 for a 5% tip but that would add a 400% tip. So I would edit total_due calculation

total_due = meal_plus_vat * (1 + tip / 100)

 

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×