Python Assignment - 0744
Python Assignment - 0744
Python Assignment
Ans.1 # To search a number from the list
s=True
while(s==True):
print("Lets make a list")
a = int(input("Enter 1st number"))
b = int(input("Enter 2nd number"))
c = int(input("Enter 3rd number"))
d = int(input("Enter 4th number"))
x = int(input("Enter the number you want to search"))
y = [a, b, c, d]
def find(x):
if x in y:
print('Yes, the number is in the given list')
else:
print("The number is not in the list try again")
find(x)
ans=int(input("Enter 1 to continue, 0 to exit"))
if ans==1:
s=True
print("continue")
print(" ")
else:
s=False
print("Exit")
Output:
Lets make a list
Exit
sorted_list = sorted(list)
print("The Sorted list in ASCENDING ORDER is: ")
print(sorted_list)
print()
Output:
The Original list is:
[10, 30, 90, 40, 20, 60, 80, 70, 50, 100]
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
Output:
The first list is :
['1', '2', '3', '4', '5', '6', '7', 'RM', 'Jin', 'Suga', 'Jhope', 'Jimin', 'V', 'Jungkook']
for r in Result:
print(r)
Output:
The first matrix is :
[3, 2, 7]
[3, 9, 7]
for r in Result:
print(r)
Output:
The first matrix is :
[2, 0, 12]
[0, 20, 6]
Output:
Diagonal elements of the matrix are :
3
The sum of diagonal elements are
Output:
Elements of the matrix are :
29
:param n: Integer
:return: n * n-1 * n-2 * n-3*.....1
"""
if n==1:
return 1
else:
return n*factorial_recursive(n-1)
flag=True
while(flag==True):
number = int(input("Enter the number"))
print("Factorial using recursive method", factorial_recursive(number))
ans = int(input("Enter(1 to continue) OR (Enter 0 to exit):"))
if (ans == 1):
flag = True
print("continue")
print("")
else:
flag = False
print("Exit")
Output:
Enter the number 5
Exit
elif b>a:
print("First number is smaller than second number")
else:
print("inavalid input")
Output:
Enter first number 5
Output:
Enter the length of the rectangle 6
x=(int(input("Enter the number you want to find the square and cube")))
print("The square of the number is ",square(x))
print("The cube of the number is",cube(x))
Output:
Enter the number you want to find the square and cube 5
The number is 25
Output:
Enter the temperature in celsius 50
Output:
Enter your number 60
Output:
Enter first number 5
Output:
Enter the day of the week 5
The name of the day is Friday
Output:
Lets find the number of days in a month
Output:
1
Output:
55
Ans.19 # To find the sum of digits of a number
n=int(input("Enter the number"))
sum = 0
while(n > 0):
digit = n%10
sum = sum + digit
n =n//10
print(sum)
Output:
Enter the number 234
Output:
Enter your number 456
654
print(sum)
Output:
50
:param n: Integer
:return: n * n-1 * n-2 * n-3*.....1
"""
if n==1:
return 1
else:
return n*factorial_recursive(n-1)
flag=True
while(flag==True):
number = int(input("enter the number"))
print("Factorial using recursive method", factorial_recursive(number))
ans = int(input("Enter(1 to continue) OR (Enter 0 to exit):"))
if (ans == 1):
flag = True
print("continue")
print("")
else:
flag = False
print("Exit")
Output:
enter the number 7
Exit
if(sum==copy_n):
print(f"{copy_n} is an armstrong number")
else:
print(f"{copy_n} is not an armstrong number")
Output:
Enter the number
153
i=0
while(i<5):
i=i+1
print(square(i))
Output:
1
16
25
print(sum)
Output:
30
sum=0
for i in list1:
sum=sum+i
print(sum)
Output:
68
if bool_val=="0":
for i in range(num,0,-1):
print("*"*i)
Output:
Pattern printing
Enter how many rows you want to print :
5
Enter 1 or 0
1 for True value or 0 for False:
0
*****
****
***
**
*
if (flag):
print("The number", n, "is not a PRIME Number")
else:
print("The number", n, "is a PRIME Number")
Output:
Enter the number: 7
:param n: Integer
:return: n * n-1 * n-2 * n-3*.....1
"""
if n==1:
return 1
else:
return n*factorial_recursive(n-1)
flag=True
while(flag==True):
number = int(input("enter the number"))
print("Factorial using recursive method", factorial_recursive(number))
ans = int(input("Enter(1 to continue) OR (Enter 0 to exit):"))
if (ans == 1):
flag = True
print("continue")
print("")
else:
flag = False
print("Exit")
Output:
enter the number 4
Exit