Function Return Values

Welcome to the lesson on function return values. Now we unlock a deeper level of function using.

` ˙⋆˖⁺‧₊☽◯☾₊‧⁺˖⋆˙ `

When a function is called, it can return a value back to the caller. This value can be stored in a variable, used in an expression, or passed to another function.

Data Type Conversion

Functions with return value:

Using the input() Function

The input() function reads a string from user input. When input() is called, the program waits for the user to type something and press Enter. The function then returns the input as a string.

#Example: name = input() # User input: Tom Riddle print("Name's " + name) # Output: Name's Tom Riddle
Output:
Name's Tom Riddle

In this example, the user is prompted to enter their name. The input is stored in the variable name and then printed.

Combining Functions

Functions can be nested, meaning you can use one function inside another. This allows you to process the return value of one function with another function.

Let's see some examples:

#Example: Using input() with int() and float() age = int(input()) height = float(input()) print("Your age is: " + str(age)) print("Your height is: " + str(height))

In these examples, the input() function reads user input as a string. The int() or float() function then converts this string to an integer or float, respectively. The resulting values are stored in variables and printed.

Practical Application

You are tasked with evaluating the magical potency of different artifacts. Create a spell that asks for the name of an artifact, its age in years, and its magical potency (on a scale of 0.0 to 100.0). Display the artifact's information in a formatted message.

⋆˖⁺‧₊ Use input(), int(), float(), and str() to capture and display artifact information. ₊‧⁺˖⋆

Sample Output:
Artifact: Divine Rapier
Age: 1674 years
Potency: 100.0
#Type your code below: