Assignment Functions
Assignment Functions
Q.1)
#Code By Vedant Kale H3
def cal_sum_product(x1,x2,x3):
print("The sum is:",x1+x2+x3);
print("The product is:",x1*x2*x3);
x1=int(input("Enter 1st number:"))
x2=int(input("Enter 2nd number:"))
x3=int(input("Enter 3rd number:"))
cal_sum_product(x1,x2,x3);
Output:
Output:
Q.4) # Write a function that takes an integer n and returns the n-th level of Pascal's triangle.
#code by Vedant Kale H3
def pascals_triangle(level):
triangle = [[1]]
for i in range(1, level):
row = [1]
for j in range(1, i):
row.append(triangle[i - 1][j - 1] + triangle[i - 1][j])
row.append(1)
triangle.append(row)
return triangle
def print_pascals_triangle(triangle):
for row in triangle:
print(" ".join(map(str, row)))
level = 5
triangle = pascals_triangle(level)
print_pascals_triangle(triangle)
Output:
Output:
Output:
Output: