From my previous post: Python Tutorial 03 : basic arithmetic operator and create the first Python Function, we have directly populated the result into the screen using the print function with multiple arguments. Should we concatenate the result into one single string before populate it to the screen?
Let’s review the code we have used from our previous example.
Python use the “+” operator to concentrate strings. However, it our case the variable “area”, “Base” and “Height” are actually an integer. Therefore, we have to convert the integer to string before we can concentrate the string. To convert an integer to a string, we can use the “Str()” function. The Str function is a build-in function that convert an object into string
Let’s put the output string into a new variable called “result”. Following is the program:
Following is the result:
The are of a triangle of base 20 and height 40 is 400.0