Day 2: Operators

  • Instructions:
    • Complete the solve function
      • calculate tip, given tip percentage
      • calculate tax, given tax percentage
      • sum the meal cost, tip, and tax and round to the nearest integer
      • print the total
    Excercise
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the 'solve' function below.
    
    # The function accepts following parameters:
    #  1. DOUBLE meal_cost
    #  2. INTEGER tip_percent
    #  3. INTEGER tax_percent
    
    def solve(meal_cost, tip_percent, tax_percent):
        # Write your code here
    
    if __name__ == '__main__':
        meal_cost = float(input().strip())
    
        tip_percent = int(input().strip())
    
        tax_percent = int(input().strip())
    
        solve(meal_cost, tip_percent, tax_percent)
    
    Solution
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the 'solve' function below.
    
    # The function accepts following parameters:
    #  1. DOUBLE meal_cost
    #  2. INTEGER tip_percent
    #  3. INTEGER tax_percent
    
    def solve(meal_cost, tip_percent, tax_percent):
        tip = meal_cost/100*tip_percent
        tax = tax_percent/100*meal_cost
        total = round(meal_cost + tip + tax)
        print(total)
    
    if __name__ == '__main__':
        meal_cost = float(input().strip())
    
        tip_percent = int(input().strip())
    
        tax_percent = int(input().strip())
    
        solve(meal_cost, tip_percent, tax_percent)