Jovian
⭐️
Sign In

Write a function to compute 5/0 and use try/except to catch the exceptions.

In [3]:
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"]

In [4]:
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.

In [5]:
import numpy as np
x = np.array([1, 2, 3, 4, 5, 6])
N = 3
np.vander(x, N)
np.column_stack([x**(N-1-i) for i in range(N)])
np.vander(x)
np.vander(x, increasing=True)
Out[5]:
array([[   1,    1,    1,    1,    1,    1],
       [   1,    2,    4,    8,   16,   32],
       [   1,    3,    9,   27,   81,  243],
       [   1,    4,   16,   64,  256, 1024],
       [   1,    5,   25,  125,  625, 3125],
       [   1,    6,   36,  216, 1296, 7776]])
In [6]:
import jovian

In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: