0% found this document useful (0 votes)
10 views

Assignment Functions

Uploaded by

vedantkale362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment Functions

Uploaded by

vedantkale362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment Question and Answer

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:

Q.2) #code by Vedant Kale H3


def tuplelist():
result = [(x, x*2, x*3) for x in range(1, 11)]
return result
tuples_list = tuplelist()
for item in tuples_list:
print(item)
Output:
Q.3) #code by Vedant Kale H3
def generate_pascals_triangle(level):
triangle = []
for i in range(level):
row = [None] * (i + 1)
row[0], row[-1] = 1, 1
for j in range(1, len(row) - 1):
row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j]
triangle.append(row)
return triangle
def print_pascals_triangle(triangle):
for row in triangle:
print(" ".join(map(str, row)).center(len(triangle[-1])*6))
level = 5
triangle = generate_pascals_triangle(level)
print_pascals_triangle(triangle)

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:

Q.5) #code by Vedant Kale H3


def count_lower_upper(stri):
d = {"Uppercase": 0, "lowercase": 0}
for c in stri:
if c.isupper():
d["Uppercase"] += 1
elif c.islower():
d["lowercase"] += 1
print("original string:", stri)
print("no. of Upper case:", d["Uppercase"])
print("no. of Lower case:", d["lowercase"])
str1 = "Vedant Kale"
count_lower_upper(str1)

Output:

Q.6) #code by Vedant Kale H3


def create_list(l1,l2):
l3=set(l1)&set(l2);
return l3;
l1=[10,20,30,40,50]
l2=[30,40,50,60,70]

print("Intersection of two lists are:",create_list(l1,l2));

Output:

Q.7) #code by Vedant Kale H3


def sum_of_digits(n):
if n < 10:
return n
else:
return n % 10 + sum_of_digits(n // 10)

number = int(input("Enter a 5-digit positive integer number: "))

if 10000 <= number <= 99999:


print("Sum of digits:", sum_of_digits(number))
else:
print("Please input a 5-digit number.")

Output:

Q.8) #Code by Vedant Kale H3


def sanitize_list(list1):
s=set(list1);
ln=list(s);
print("The list is:",ln);
l=[10,20,30,10,40,50];
sanitize_list(l);
Output:

You might also like