CSSE1001/7030 Week 3 每周题库 · Functions & If-Statements 函数与条件分支
Week 3 精选练习:函数定义、返回值与引用、if/elif/else 条件分支。Curated practice on functions, return values and if-statements.
What is output after the following code is executed?
Create a function that takes a boolean variable flag and returns it as a string. Examples bool_to_string(True) ➞ "True" bool_to_string(False) ➞ "False"
Create a function that returns True when num1 is equal to num2; otherwise return False. is_same_num(4, 8) ➞ False is_same_num(2, 2) ➞ True is_same_num(2, "2") ➞ False
Create a function that takes two arguments. Both arguments are integers, a and b. Return True if one of them is 10 or if their sum is 10. makes10(9, 10) ➞ True makes10(9, 9) ➞ False makes10(1, 9) ➞ True
Given a string, return True if its length is even or False if the length is odd. Examples odd_or_even("apples") ➞ True # The word "apples" has 6 characters. # 6 is an even number, so the program outputs True. odd_or_even("pears") ➞ False # "pears" has 5 letters, and 5 is odd. # Therefore the program outputs False. odd_or_even("cherry") ➞ True
你的进度
已练 0 / 40 · 正确率 0%