Python 3エンジニア認定基礎試験-関数(キーワード引数)-

1. 
次のコードを実行したときの出力結果は何でしょうか?

def calculate_area(length=5, width=3):
return length * width

print(calculate_area(width=4))

2. 
次のコードを実行したときの出力結果は何でしょうか?

def summarize(name, hobby="reading", age=18):
return f"{name}, {age} years old, likes {hobby}."

print(summarize("Emily", hobby="swimming"))

3. 
次のコードを実行した場合、出力結果として正しいものを選んでください。

def describe_person(name, age=30, country="Japan"):
print(f"{name} is {age} years old and lives in {country}.")

describe_person("Bob", country="USA")

4. 
次のコードを実行したときの出力結果は何でしょうか?

def divide(a, b=1):
return a / b

print(divide(10, b=2))

5. 
次のコードを実行したときの出力結果は何でしょうか?

def order_summary(item, quantity=1, price=100):
total = quantity * price
return f"Order: {item}, Quantity: {quantity}, Total: {total}"

print(order_summary("Notebook", quantity=2))

6. 
キーワード引数に関する正しい説明はどれですか?

7. 
次のコードを実行した場合、出力結果として正しいものを選んでください。

def show_info(name="John", age=25):
print(f"{name} is {age} years old.")

show_info(age=30)

8. 
次のコードを実行したときの出力結果は何でしょうか?

def rectangle_area(length=10, width=2):
return length * width

print(rectangle_area(width=5))

9. 
次のコードを実行したときの出力結果は何でしょうか?

def add_numbers(a, b, show_sum=False):
result = a + b
if show_sum:
return f"The sum is {result}."
return result

print(add_numbers(7, 3, show_sum=True))

10. 
次のコードを実行したときの出力結果は何でしょうか?

def greet(name, message="Welcome", punctuation="!"):
return f"{message}, {name}{punctuation}"

print(greet("Alice", punctuation="!!!"))

11. 
次のコードを実行したときの出力結果は何でしょうか?

def power(base, exponent=2):
return base ** exponent

print(power(3, exponent=3))

12. 
次のコードを実行した場合、出力結果として正しいものを選んでください。

def calculate_total(price, tax=0.1, discount=0):
return price + (price * tax) - discount

print(calculate_total(100, discount=10))

13. 
次のコードに関する正しい説明はどれですか?

def greet(name, message="Hello"):
print(f"{message}, {name}!")

greet(name="Alice", message="Hi")

14. 
次のコードを実行したときの出力結果は何でしょうか?

def repeat_string(s, times=3, separator=" "):
return separator.join([s] * times)

print(repeat_string("Hi", times=2))

15. 
次のコードを実行した場合、エラーが発生する理由として正しいものを選んでください。

def example_function(a, b, c):
print(a, b, c)

example_function(a=1, 2, c=3)

16. 
キーワード引数を使用する際のルールとして正しいものはどれですか?

17. 
次のコードを実行したときの出力結果は何でしょうか?

def format_text(text, uppercase=False, exclamation=False):
if uppercase:
text = text.upper()
if exclamation:
text += "!"
return text

print(format_text("hello", uppercase=True, exclamation=True))

18. 
次のコードを実行したときの出力結果は何でしょうか?

def introduce(name, age, city="Unknown"):
return f"{name} is {age} years old and lives in {city}."

print(introduce("Sam", 30))

19. 
次のコードを実行した場合、出力結果として正しいものを選んでください。

def multiply(a, b=2):
return a * b

print(multiply(5, b=3))

20. 
次のコードを実行したときの出力結果は何でしょうか?

def build_profile(first_name, last_name, age=25, country="Japan"):
return f"{first_name} {last_name}, {age} years old, from {country}"

print(build_profile("Tom", "Smith", country="USA"))

コメントを残すにはログインしてください。