Question: Q 1 : In the code, we are calling two functions, greet ( ) and say _ goodbye ( ) . - The greet (

Q1: In the code, we are calling two functions, greet() and say_goodbye().
- The greet() function is already defined but it has a bug. It should print "Hello, World!".
- The say_goodbye() function is not defined. Define it so that it prints "Goodbye, World!".
def greet():
print("Hello, World!")
# don't modify below this line
greet()
say_goodbye()
Q2: There is a bug in the code below. Can you fix it so that the output is:
```
10
20
```
print_number(10)
print_number(20)
def print_number(k):
print(k)
Q3: n the code, define a function called farewell, which takes a single parameter. The function should print "Goodbye, " followed by the parameter. Then use this function so that the output is:
```
Goodbye, Bob
Goodbye, Charlie
Goodbye, Lisa
```
# don't modify below this line
farewell("Lisa")
Q4: In the code, define two functions, two_sum, and three_sum. The two_sum function should take two parameters and print their sum. The three_sum function should take three parameters and print their sum.
Finally, call two_sum with the arguments 7,10 and after that call three_sum with the arguments 3,5,8.
# do not modify below this line
two_sum(10,9)
three_sum(5,14,6)
Q5: In the code create a function named product that accepts two parameters and returns their product.
# don't modify below this line
print(product(2,4))
print(product(8,2))
print(product(4,8))
print(product(8,8))
Q6: In the code, call the function greet with the argument "Lisa". Then print the type of the return value of the function.
Hint: You can get the type of a value with the type() function.
def greet(name) :
print("Hello,"+ name)
Q7: To prove that the variable k inside the function is different than the one outside, consider this code:
```
def add_one(k):
k = k +1
print(k)
k =10
add_one(k) # Output: 11
print(k) # Output: ?
```
What do you think the output of the last print statement will be? Will it be 10 or 11? Run the code to find out.
Q8: There's a bug in the code below, if you try to run it you'll see a NameError. Can you fix it so that the output is:
```
100
100
```
k =100
def print_local_variable(num) :
print(num)
print_local_variable(k)
print(num)
Q9: In the code below, update the function greet() so that the second parameter has a default value of "!".
def greet(name, punctuation) :
print("Hello,"+ name + punctuation)
greet("World","!")
greet("World")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!