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:
- The code initializes two variables, priceIcecream and priceBrownie, with the respective prices.
- It then adds the two variables together and stores the result in the totalPrice variable.
- 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