【hackerrank】-Day 2: Operators

24 篇文章 0 订阅
24 篇文章 0 订阅

30-operators
Objective
In this challenge, you’ll work with arithmetic operators. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal’s total cost.

Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!

Input Format

There are lines of numeric input:
The first line has a double, (the cost of the meal before tax and tip).
The second line has an integer, (the percentage of being added as tip).
The third line has an integer, (the percentage of being added as tax).

Output Format

Print The total meal cost is totalCost dollars., where is the rounded integer result of the entire bill ( with added tax and tip).

Sample Input

12.00
20
8
Sample Output

The total meal cost is 15 dollars.
Explanation
Given:
Calculations:

We round to the nearest dollar (integer) and then print our result:
The total meal cost is 15 dollars.


Current Buffer (saved locally, editable)

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent):
    totalCost = tip = tax = 0
    tip = meal_cost*(tip_percent/100)
    tax = meal_cost*(tax_percent/100)
    totalCost = meal_cost + tip + tax
    # print(round(totalCost))
    return int(round(totalCost))

if __name__ == '__main__':
    meal_cost = float(input())
    tip_percent = int(input())
    tax_percent = int(input())
    totalCost = solve(meal_cost, tip_percent, tax_percent)
    print("The total meal cost is %d dollars." % totalCost)

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Testcase 0 Testcase 1
Input (stdin)
12.00
20
8
Your Output (stdout)
The total meal cost is 15 dollars.
Expected Output
The total meal cost is 15 dollars.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值