Table of Contents

Explicit type casting | Pictoblox

Example Description
Learn how to use explicit type casting in Python to calculate the total price by adding two price variables. Example code included

Introduction:

This Python code demonstrates the concept of explicit type casting. It calculates the total price by adding two price variables, priceIcecream and priceBrownie, and then converts the result to a string for display.

Code:

priceIcecream = 25
priceBrownie = 45
totalPrice = priceIcecream + priceBrownie
print("The total in Rs." + str(totalPrice))

Logic:

  1. The code initializes two variables, priceIcecream and priceBrownie, with the respective prices.
  2. It then adds the two variables together and stores the result in the totalPrice variable.
  3. Finally, it converts the totalPrice to a string using the str() function and concatenates it with the string “The total in Rs.” to form the desired output.

Output:

>> The total in Rs.70