>>> import math
>>> ball = int(input("Enter a positive number: "))
>>> bucket = math.sqrt(n)
>>> print(f'Square Root of {n} is {bucket}')
Handling Exceptions
Fill in the blanks to make a program that takes number of students
as input and calculates average marks
total_marks = 468
try:
input = "10"
# typecast input to correct data type
number_of_students = (input)
average_marks = total_marks/number_of_students
except :
print("Number of students has to be an Integer")
finally:
print("Found the average marks")
Fill in the blanks to make a program that finds out the employee
ID of given employee
IDs = {'Adyansh':1,'Karthik':2,'Pratistha':3}
try:
# Calculate employee_id
employee_id = IDs[]
print(f'ID is {employee_id}')
except :
print("Employee not found")
finally:
print("Found the employee ID")
Generate an Exception
Can you generate an Index Error?
>>> bucket = [1,2,3]
>>> bucket_idx = int(input("Assign a bucket to the ball: "))
>>> ball = bucket[bucket_idx]
Handling Exceptions
Fill in the blanks to make a program that puts value at index position in array
array = [1,123,1,2,5,14,2,41,5,1]
try:
index =
value = 50
array[index] = value
except :
print("Index does not exist")
except :
print("Please enter numbers only")
Fill in the blanks to make a program that splits money between friends
total_bill = 1000
try:
number_of_people =
split = total_bill/number_of_people
print(f"Each of you has to pay ${split}")
except :
print("Split cannot be done between 0 people")
finally:
print("Split has been done")