Day 2 of #100DaysOfCode: - Shopping Bill Calculator

On Day 2 of #100DaysOfCode, I have created a mini project called shopping bill calculator. This includes the following python concepts from Dr Angela Yu's 100DaysOfCode: The Complete Python Bootcamp yesterday:

  • Python Data Types

  • Mathematical Operations

  • Number Manipulations and F strings

Shopping Bill Calculator program allows the shop assistant to input the prices of the items customers want to purchase. It then calculates the total cost with applied tax. Afterwards, the shop assistant prompts the customer to define the number of people that are contributing to the total cost. Once provided, it calculates the amount each person needs to pay for those items.

Python Concepts Used

Python Data Types

In this program, the input of both items is currently assigned as strings. Prior to calculating the total price before VAT, these strings are converted to floats using float() function. Likewise, the input for the number of people contributing towards the total cost. Once entered, the program prints the amount each person requires to pay for these items.

item_1 = input("\nWhat is the price of item 1? \n")
item_2 = input("\nWhat is the price of item 2? \n")

float(item_1)
float(item_2)

number_of_people = input("\nHow many people are contributing towards the total price? \n")

int(number_of_people)

Mathematical Operators

The addition operator is used to calculate the total cost and store it into a into a new variable called total_cost_before_vat. Afterwards, to calculate the output of the newly created variable total_cost_after_vat, it uses PEMDAS method which determines the order of operations as follows - Parameters, Exponents, Multiplication, Division, Addition and Subtraction. Within this program, it computes the value inside the brackets first and then calculates the multiplication to output the total amount after tax.

#1st Mathematical Operator

total_cost_before_vat = float(item_1) + float(item_2)

#2nd Mathematical Operator

total_cost_after_vat = total_cost_before_vat * (1 + vat_rate)

Number Manipulations and F strings

Number manipulation is used in this program by including the round() function in both print functions and inside the parenthesis, it includes the total_after_vat and total_share. It also includes the number 2 after the comma to round the both of those totals into two decimal places. F strings are used in this program to not only remove the load of manually converting these variables total_after_vat and total_share into a string but it is also making it easier to print the output using multiple data types.

print(f"\nThe total cost after VAT is £{round(total_cost_after_vat,2)}.")
print(f"\nEach person contributes: £{round(total_amount_share,2)}\n")

In conclusion, I really enjoyed creating this program and it prints the desired output I wanted it to and learned a lot on Day 2 of #100DaysOfCode. For the full code of this project, please visit my GitHub - https://github.com/keiransystem14/Python100daysofcode/tree/main/Day%202%20Project%20-%20Shopping%20Bill%20Calculator