PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# `return` can only be used inside functions.
# sample: pass (2) values to a function, calculate the average of them and return the result back to the caller. the result will be stored in the variable `result` and will be output in the last line of the code.
# a return statement also terminates the function and leaves it.
def average_temp(temp1_, temp2_):
average = (temp1_ + temp2_) / 2
return average
temp1 = float(input())
temp2 = float(input())
result = average_temp(temp1, temp2)
print(result)
# we can also return *mutiple values* to the caller like: average, largest number, ...
def calculate_temp(temp1_, temp2_):
average = (temp1_ + temp2_) / 2
largest = temp1_ if temp1_ > temp2_ else temp2_
return average, largest
temp1 = float(input())
temp2 = float(input())
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run