SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Programming
Exercise:
Programming Excercises
Question:5 | ISBN:978013274719 | Edition: 6

Question

(Financial application: calculate tips) Write a program that reads the subtotal and the gratuity rate and computes the gratuity and total. For example, if the user enters 10 for the subtotal and 15% for the gratuity rate, the program displays 1.5 as the gratuity and 11.5 as the total. Here is a sample run:

Enter the subtotal and a gratuity rate:15.69, 15
The gratuity is 2.35 and the total is 18.04

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

The below program reads the subtotal and the gratuity rate and computes the gratuity and total:

CODE WITH COMMENTS:

subtotal=float(input("enter the value of subtotal:")) #enter the input value subtotal
gratuity_rate=float(input("enter the value of gratuity rate:")) #enter another input value gratuity rate
gratuity=(gratuity_rate/100)*subtotal  #formula for gratuity
total=gratuity+subtotal                 #formula for total
print("the gratuity is",int(gratuity*100)/100,"and the total is",int(total*100)/100 )  #print the required output

OUTPUT:

enter the value of subtotal:15.69
enter the value of gratuity rate:15
the gratuity is 2.35 and the total is 18.04

enter the value of subtotal:10
enter the value of gratuity rate:15
the gratuity is 1.5 and the total is 11.5

 

0 0

Discussions

Post the discussion to improve the above solution.