Learn practical skills, build real-world projects, and advance your career

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

Write a function so that the columns of the output matrix are powers of the input vector.

The order of the powers is determined by the increasing boolean argument. Specifically, when

increasing is False, the i-th output column is the input vector raised element-wise to the power

of N - i - 1.