Ai Python Programs Word File
Ai Python Programs Word File
PROGRAMS
#1.WAP TO ACCEPT ANY NUMBER AND PRINT ITS SQUARE, CUBE AND HALF
INPUT
n1=int(input('Enter a number'))
S=n1*n1
C=n1*n1*n1
H=n1/2
print("Square of the number is",S)
print("Cube of the number is",C)
print("Half of the number is",H)
OUTPUT
Enter a number23
Square of the number is 529
Cube of the number is 12167
Half of the number is 11.5
#2.WAP TO ACCEPT THE MARKS OF A STUDENT IN ANY 3 SUBJECTS AND CALCULATE TOTAL AND AVERAGE OF
MARKS
INPUT
M1 = int(input("Enter marks in English: "))
M2 = int(input("Enter marks in Hindi: "))
M3 = int(input("Enter marks in Maths: "))
T = M1 + M2 + M3
A=T/3
print("Total marks of student is", T)
print("Average marks of student is", A)
OUTPUT
Enter marks in English: 79
Enter marks in Hindi: 71
Enter marks in Maths: 80
Total marks of student is 230
Average marks of student is 76.66666666666667
#3.WAP to enter no. of days and calculate the no. of years, no. of months, and no. of days left
INPUT
D = int(input("Enter no. of days: "))
Y= D // 365
M= (D - (Y * 365)) // 30
LD = D - (Y * 365) - (M * 30)
print("No. of years are:", Y)
print("No. of months are:", M)
print("No. of days left:", LD)
OUTPUT
Enter no. of days: 4567
No. of years are: 12
No. of months are: 6
No. of days left: 7
#8.Write a Python program to accept the name, age, and nationality of a person. If the age is more than or equal
to 18 years and nationality is "Indian," display "You are eligible to vote." Otherwise, display "You are not eligible
to vote."
INPUT
a = input("Enter name: ")
Ag = int(input("Enter your age: "))
na = input("Enter your nationality: ")
if Ag >= 18 and na == "Indian":
print("Person is eligible to vote")
else:
print("Person is not eligible to vote")
OUTPUT
Enter name: Prateek
Enter your age: 14
Enter your nationality: INDIAN
Person is not eligible to vote
#10 WAP TO ENTER ANY NUMBER AND CHECK WHETHER IT IS NEGATIVE POSITIVE OR ZERO
INPUT
n=int(input('Enter a number:'))
if n>0:
print(n,'is a positive number')
elif n<0:
print(n,'is a negative number')
else:
print(n,'is zero')
OUTPUT
Enter a number:0
0 is zero
#11. WAP TO ACCEPT ANY TWO NUMBERS AND PRINT THE LARGEST NUMBER
INPUT
n1=int(input('Enter a number'))
n2=int(input('Enter a number'))
if n1>n2:
print(n1,'is the larger number')
else:
print(n2,'is the larger number')
OUTPUT
Enter a number79
Enter a number35
79 is the larger number
#12Write a program to input billing amount and gender, If the billing amount is more than 10000 and gender is
male, then discount is 15% otherwise discount is 10%. Calculate the billing amount accordingly.
INPUT
A=int(input('Enter billing amount:'))
G=input('Gender(Write M or F):')
if A>10000:
if G== 'M':
print('Amount after 15% discount is:',A-(0.15*A))
else:
print('Amount after 10% discount is:',A-(0.1*A))
else:
print('Sorry! No Discount')
OUTPUT
Enter billing amount:455657
Gender(Write M or F):F
Amount after 10% discount is: 410091.3
#13WAP TO ACCEPT YOUR NAME, AGE AND CLASS AND PRINT IT FOR 10 TIMES
INPUT
n=input('Enter your name')
ag=int(input('Enter you age'))
c=input('Enter your class')
for i in range(1,11,1):
print('My name is',n)
print('My age is',ag)
print('My class is',c)
OUTPUT
Enter your namePrateek
Enter you age14
Enter your class9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
My name is Prateek
My age is 14
My class is 9
18. Write a program to enter any number and print its factors.
INPUT
N=int(input('Enter a number:')) for i in range(1,N+1,1):
if N%i==0: print(i)
OUTPUT
Enter a number:56
247
8
14
28
56
INPUT
c=1 while c<=10:
print(c) c=c+1
OUTPUT
12
34
56789
10
20. Write a program to create a list of first 10 even numbers, add 1 to each item and print the final
list.
INPUT
L1=[] for x in range(2,21,2):
L1.append(x) print(L1) for i in
range(len(L1)): L1[i]+=1 print(L1)
OUTPUT
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
21.Write a program to input two numbers and an
operator from the user. Display the result calculated
based on the operator entered.
INPUT
N1=int(input('Enter a number:')) N2=int(input('Enter a
number:')) O=input('Enter a operator(+,-,*,/ only):') if
O=='+':
print('The addition is',N1+N2) elif O=='-':
print('The subtraction is',N1-N2) elif O=='*':
print('The multiplication is',N1*N2) elif O=='/':
print('The division is',N1/N2) else:
print('No Result!')
OUTPUT
Enter a number:45
Enter a number:52
Enter a operator(+,-,*,/ only):*
The multiplication is 2340
INPUT
A=int(input('Enter billing amount:'))
G=input('Gender(Write M or F):') if A>10000: if G== 'M':
print('Amount after 15% discount is:',A-(0.15*A))
else: print('Amount after 10% discount is:',A-(0.1*A))
else:
print('Sorry! No Discount')
OUTPUT
Enter billing amount:455657
Gender(Write M or F):F
Amount after 10% discount is: 410091.3
23.Write a program to print sum of first 10 natural
numbers.
INPUT
s=0 for i in range(1,11): s+=i print('The sum is',s)
OUTPUT
The sum is 55
24.Write a program to calculate the sum of digits of a
number.
**Input**
num = int(input("Enter a number: "))
sum_digits = 0
while num > 0: sum_digits += num % 10
num //= 10
print("Sum of digits:", sum_digits)
**Output**
Enter a number: 123
Sum of digits: 6