Loading...
Loading...
Test your knowledge of functions
1. What keyword defines a function?
2. What does this function call print?
def greet():
print("Hello!")
greet()3. What is name called in: def greet(name):?
4. What does return do?
5. What is the output?
def add(a, b):
return a + b
result = add(2, 3)
print(result * 2)6. What is x after this code?
def calc(n):
n * 2
x = calc(5)7. What does the second call print?
def greet(name="Guest"):
print(f"Hello, {name}!")
greet("Alice")
greet()8. Which function header is valid?
9. What is output?
def check(n):
if n > 0:
return "Positive"
return "Not positive"
print(check(-5))10. What does this do?
def repeat(word="Python", count=2):
return word * count