Program File
Program File
factorial = 1
if num < 0:
elif num == 0:
else:
factorial = factorial*i
OUTPUT:
Enter a number: 5
if (num % 2) == 0:
else:
OUTPUT:
Enter a number: 45
45 is odd
Enter a number: 22
22 is even
PROGRAM 3
3. Write a Python program to take a number as input from the user and check whether the
number is Prime or not.
if num == 0 or num == 1:
for i in range(2,num):
if (num % i) == 0:
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number") # if input number is less than or equal to 1, it is not prime
else:
OUTPUT:
Enter a number: 45
3 times 15 is 45
Enter a number: 13
13 is a prime number
PROGRAM 4
while number != 0:
print('The end.')
OUTPUT:
Enter a number: 44
Enter a number: 23
Enter a number: 12
Enter a number: 0
The end.
5. Python program to enter an operator by the user and perform the mathematical
operations according to the operator entered
x=5
y = 10
match operator:
case '+':
result = x + y
case '-':
result = x - y
case '*':
result = x * y
case '/':
result = x / y
print(result)
OTPUT:
Enter an operator: +
15
Enter an operator: -
-5
Enter an operator: *
50
Enter an operator: /
0.5
PROGRAM 6
6. A menu based Python program to enter a subject and marks by the user and print
according to the following cases:
Score Print
Physics or chemistry or biology>= 80 Excellent in Science!
English or Grammar >=80 Excellent in English!
Mathematics>= 80 Excellent in Maths!
Default case Needs Improvement!
match subject:
print("Excellent in Science!")
print("Excellent in English!")
print("Excellent in Maths!")
case _:
OUTPUT:
Enter a score: 45
Enter a score: 89
Excellent in Maths!
PROGRAM 7
row=5
for i in range(1,row+1):
for j in range(1,i+1):
print("*",end='')
print()
OUTPUT:
**
***
****
*****
Program:
row=6
for i in range(row):
for j in range(i):
print(i,end='')
print('')
OUTPUT
22
333
4444
55555
PROGRAM:
row=5
for i in range(1,row+1):
for j in range(1,i+1):
print(j,end='')
print()
OUTPUT:
12
123
1234
12345
row=6
b=0
for i in range(row,0,-1):
b+=1
for j in range(1,i+1):
print(b,end='')
print('')
OUTPUT
111111
22222
3333
444
55
PROGRAM:
row=5
num=row
for i in range(row,0,-1):
for j in range(0,i):
print(num,end='')
print(' ')
OUTPUT
55555
5555
555
55
import numpy as np
x = [0,1,2,3,4]
y = [0,1,2,3,4]
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Straight line')
plt.show()
OUTPUT
PROGRAM 13
13. Write a program to create a list of all students in your class and sort them in alphabetical
order.
students=['John','Asit','Shobhit','Eva','Dinesh','Garima']
sorted_students= sorted(students)
print(students)
OUTPUT
Asit
Dinesh
Eva
Garima
John
Shobhit
PROGRAM 14
import numpy as np
print(arr)
print(type(arr))
OUTPUT:
[1 2 3 4 5]
<class 'numpy.ndarray'>
PROGRAM 15
15. Create a 3X4 D array with random integer values less than 10
import numpy as np
a= np.random.randint(10,size=(3,4))
print(a)
OUTPUT:
[[5 9 4 3]
[6 0 6 3]
[7 2 9 5]]