Category: Code Exercises

September 3, 2023

Python Tuples Exercises

What is the output of this program? students = ([“John”, “Doe”], [“Jane”, “Smith”], [“Mike”, “Johnson”]) def print_student_info(students, student_index): print(‘Student name:’, students[student_index][0]) print(‘Student lastname:’, students[student_index][1]) print_student_info(students, 2) Student name: MikeStudent lastname: Johnson Student name: JaneStudent lastname: Smith Submit What is the output of this program? students = ([“John”, “Doe”], [“Jane”, “Smith”], [“Mike”, “Johnson”]) def print_student_info(students, student_index): […]

September 3, 2023

Python Tuples Exercises

How do you describe the contents of the students? students = [ (“John”, 20, “Computer Science”), (“Emily”, 22, “Mathematics”), (“Michael”, 21, “Physics”), (“Sarah”, 19, “Biology”) ] A list of tuples A tuple of lists Submit What is the output of this program? students = [ (“John”, 20, “Computer Science”), (“Emily”, 22, “Mathematics”), (“Michael”, 21, “Physics”), […]

September 1, 2023

Python Lists Exercises

Complete the list definition. user_permissions = 2’Read’, ‘Write’, ‘Publish’, ‘Delete’] Submit Display the first permission in the list. user_permissions = [‘Read’, ‘Write’, ‘Publish’, ‘Delete’] first_permission = user_permissions[”] print(first_permission) Submit Display the last permission in the list. user_permissions = [‘Read’, ‘Write’, ‘Publish’, ‘Delete’] last_permission = user_permissions[”] print(last_permission) Submit Find the cheapeast item in the list. item_prices […]

September 1, 2023

Python Custom Functions Exercises

Define a function that prints Hello Python! on the console. ” print_hello_python(): print(“Hello Python!”) Submit Call the function. def print_hello_python(): print(“Hello Python!”) ” ( print_hello_python ) : Submit Modify the function that accepts a string and prints it on the console. def print_string(”): print(input_string) print_string(“Hello Python!”) Submit This function takes a number and doubles it. […]

September 1, 2023

Python Conditionals Exercises

What will be the value of the letter_grade variable? exam_score = 85 program_of_study = ‘Electrical Engineering’ if program_of_study == ‘Computer Science’: if exam_score >= 90: letter_grade = ‘A’ elif exam_score >= 80: letter_grade = ‘B’ elif exam_score >= 70: letter_grade = ‘C’ elif exam_score >= 60: letter_grade = ‘D’ else: letter_grade = ‘F’ elif program_of_study […]

September 1, 2023

Python Conditionals Exercises

What will be the value of the shipping_cost variable? destination_zone = “Zone C” if destination_zone == “Zone A”: shipping_cost = 10.0 elif destination_zone == “Zone B”: shipping_cost = 15.0 elif destination_zone == “Zone C”: shipping_cost = 20.0 else: shipping_cost = 25.0 print(“The shipping cost to”, destination_zone, “is:”, shipping_cost) 20.0 25.0 Submit What will be the […]