Introduction:
This Python code demonstrates the process of type conversion between numbers and strings. It showcases how to add two numbers and concatenate a string to display the total price.
Code:
priceIcecream = 25
priceBrownie = 45
totalPrice = priceIcecream + priceBrownie
print("The total is Rs." + totalPrice )
Logic:
1. The code defines two variables, priceIcecream and priceBrownie, with their respective values.
2. It then performs addition on these variables to calculate the total price.
3. Next, it uses string concatenation to display the result as a sentence.
Output:
The output of the code will be an error due to a type mismatch. To fix this, you need to convert the totalPrice variable to a string using the str() function.
#There will be one TypeError: can only concatenate str (not “int”) to str
#Failed to execute script ‘main’ due to unhandled exception!