Tag: Python

September 5, 2023

Python Exercises to Check Your Programming Knowledge

What is the output of the round() function? market_share = 12.03298 rounded_market_share = round(market_share, 2) print(rounded_market_share) 12.2 12.03 Submit Imagine you are developing a scheduling application that allows users to create events and manage their availability. You have two sets representing the available time slots for two different users: User A and User B. Each […]

September 3, 2023

Python Exception Handling Exercises

Why do we use exception handling ? To introduce intentional errors and bugs into the code for testing purposes To handle exceptional situations and prevent crashes Submit What is the output of this code? try: num = int(“$10”) print(num) except ValueError: print(“An exception occurred. Invalid conversion to an integer!”) $10 An exception occurred. Invalid conversion […]

September 3, 2023

Python Classes Exercises

Complete the class definition. ” Employee: def __init__(self, name, position, department): self.name = name self.position = position self.department = department Submit Add a new attribute to the class. class Employee: def __init__(self, name, position, department, salary): self.name = name self.position = position self.department = department ” salary self = salary == . Submit Create a […]

September 3, 2023

Python Sets Exercises

Which of the following options correctly identifies the keys and values in the dictionary? my_dictionary = {“cat”: “meow”, “dog”: “woof”, “bird”: “tweet”} Keys: cat, dog, bird Values: meow, woof, tweet Keys: meow, woof, tweet Values: cat, dog, bird Submit Imagine you are building a task management application. You have a dictionary representing a user’s tasks, […]

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”), […]