1: How to Answer these Questions

Write functions to solve all of the questions. Here are two example questions and their solutions. Notice that the first function prints a value, the second function returns a value.

1 Hello <Name>

Write a function that accepts a name as a parameter and prints out “Hello ” <name>

1.1 Example

hello("Kim")
 *** Output ***
Hello Kim

2 Average of two numbers

Write a function that accepts two numbers and returns the average of the two numbers.

2.1 Example

print(average(3,4));
 *** Output ***
3.5

3 Solutions

1: def hello(s):
2:     print("Hello ",s)
3: 
4: def average(i,j):
5:     return (i+j)/2
6: 
7: hello("Kim")
8: print(average(3,5))

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s