1
1
7.Write a Python program to find the difference between two lists of the
same type.
Ans..
list1 = [10, 20, 30, 40, 50]
list2 = [10, 20, 30, 60, 70]
print("list1:", list1)
print("list2:", list2)
print("Difference elements:")
print(list(set(list1) - set(list2)))
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Ans..
n = 5
for i in range(n):
for j in range(i):
print('* ', end="")
print('')
for i in range(n, 0, -1):
for j in range(i):
print('* ', end="")
print('')
Ans..
temp = input("Input the temperature you like to convert? (e.g., 45F, 102C
etc.) :
degree = int(temp[:-1])
i_convention = temp[-1]
if i_convention.upper() == "C":
result = int(round((9 * degree) / 5 + 32))
o_convention = "Fahrenheit" # Set the output convention as
Fahrenheit
elif i_convention.upper() == "F":
result = int(round((degree - 32) * 5 / 9))
o_convention = "Celsius" # Set the output convention as Celsius
else:
print("Input proper convention.")
quit()
print("The temperature in", o_convention, "is", result, "degrees.")
Ans..
for i in range(4):
for j in range(0,1+i):
print(i+1,"*",end=" ")
print()
15.WAP to find the sum of n numbers and count the numbers in a list:
Ans..
a=[]
n=int(input("How many numbers?: "))
for i in range(1,n+1):
k=int(input("Enter Number: "))
a.append(k)
c=int(input("Enter the number to be counted: "))
z=int(input("Enter the number to find: "))
print("The Sum is: %d"%sum(a))
print("The No of times is: %d"%a.count(c))