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:
int (): converts a string or a float to an integer (e.g.,"123" to123 ).float (): converts a string or an integer to a float (e.g.,"5.9" to5.9 ).str (): converts a number or other data type to a string (e.g.,123 to"123" ).
Using the input () Function
The
In this example, the user is prompted to enter their name. The input is stored in the variable
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:
In these examples, the
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
Age: 1674 years
Potency: 100.0