Table of Contents
Example Description
Convert numbers and strings in Python. How to perform addition on numbers and concatenate strings to get the desired result.

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!