Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Write a function to compute 5/0 and use try/except to catch the exceptions.
def compute():
a = 5/0
try:
print(compute())
except ZeroDivisionError as ze:
print('Error: while dividing with zero it should through error')
Error: while dividing with zero it should through error
Implement a Python program to generate all sentences where subject is in ["Americans",
"Indians"] and verb is in ["Play", "watch"] and the object is in ["Baseball","cricket"].
Hint: Subject,Verb and Object should be declared in the program as shown below.
subjects=["Americans ","Indians"]
verbs=["play","watch"]
objects=["Baseball","Cricket"]
subjects=["Americans ","Indians "]
verbs=["play ","watch "]
objects=["Baseball","Cricket"]
for s in subjects:
for v in verbs:
for o in objects:
sentence = s+v+o
print(sentence)
Americans play Baseball
Americans play Cricket
Americans watch Baseball
Americans watch Cricket
Indians play Baseball
Indians play Cricket
Indians watch Baseball
Indians watch Cricket