Python: Lesson 5
Given the following code, a = ['m', 'r', 'y'] b = ['e', 'r', '!'] ab = zip (a, b) Which of the following statements will return list a to x and list b to y?
A. x, y = zip (*ab)
Given these two lists, a = ['m', 'r', 'y'] b = ['e', 'r', '!'] What does the list list_ab look like ? ab = zip (a, b) list_ab = list (ab)
D. [('m', 'e'), ('r', 'r'), ('y', '!')]
Which one of the following statements is true about the Python "lambda" construction?
Lambda is a tool for building function objects.
The following is a list of tuples: student_list=[('Kyle', '100203', 3.55), ('Jerry', '100126', 3.00), ('Alex', '100201', 2.80), ('Harry', '100138', 3.78)] What does this function call return? list1 = sorted (student_list, key=lambda s: s[2])
[('Alex', '100201', 2.8), ('Jerry', '100126', 3.0), ('Kyle', '100203', 3.55), ('Harry', '100138', 3.78)]
def get_course(): course_code = input("Enter course code: ") section_num = input("Enter section number: ") return course_code, section_num Which of the following statements will ivoke the function get_course and store the return values correctly?
course_code, section_num = get_course()
Which of the following functions displays the GPA entered by the user and also sends it to the calling function?
def get_gpa(): gpa = float(input("Enter GPA: ")) print(gpa) return gpa
Which of the following functions sends the the GPA entered by the user to the calling function?
def get_gpa(): gpa = float(input("Enter GPA: ")) return gpa
In a fitness test the heart rates before and after a 10-minute exercise are measured. Which of the following functions correctly return both heart rates?
def get_heart_rates(): hrb = int(input("Enter heart rate before exercise: ")) hra = int(input("Enter heart rate after exercise: ")) return hrb, hra
Students in a course get a P grade if they score 60 or above in the final exam and F grade if they score less than 60. Which of the following functions correctly returns the grade?
def grade_converter(score): if score >= 60: grade = 'P' else: grade = 'F' return grade def grade_converter(score): if score >= 60: return 'P' else: return 'F'
Suppose get_gpa is a value returning function that returns the GPA entered by the user. Which of the following main functions will display the gpa successfully?
def main(): gpa = get_gpa() print(gpa)