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

Ai Python Programs Word File

The document contains a series of Python programming exercises that demonstrate basic programming concepts such as input/output, arithmetic operations, loops, conditionals, and list manipulation. Each exercise includes a problem statement, sample input, and expected output. The programs cover a variety of topics including calculations, number properties, and user interactions.
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)
2 views

Ai Python Programs Word File

The document contains a series of Python programming exercises that demonstrate basic programming concepts such as input/output, arithmetic operations, loops, conditionals, and list manipulation. Each exercise includes a problem statement, sample input, and expected output. The programs cover a variety of topics including calculations, number properties, and user interactions.
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/ 10

PYTHON

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

#4.WAP TO PRINT SUM OF FIRST TEN NATURAL NUMBER


INPUT
S=0
C=1
while C<11:
S=S+C
C=C+1
print("Sum of first ten natural numbers is :", S)
OUTPUT
Sum of first ten natural numbers is : 55

#5 WAP TO ENTER ANY NUMBER AND GENERATE ITS TABLE


INTPUT
n=int(input('Enter any number'))
c=1
while c<=10:
print(n,'*',c,'=',n*c)
c=c+1
OUTPUT
Enter any number15
15 * 1 = 15
15 * 2 = 30
15 * 3 = 45
15 * 4 = 60
15 * 5 = 75
15 * 6 = 90
15 * 7 = 105
15 * 8 = 120
15 * 9 = 135
15 * 10 = 150

#6.WAP TO PRINT FIRST TEN NATURAL NUMBER


INPUT
c=1
while c<11:
print(c)
c=c+1
OUTPUT
1
2
3
4
5
6
7
8
9
10

#7.WAP TO PRINT THE PRODUCT OF FIRST SIX MULTIPLES OF THREE


INPUT
p=1
c=3
while c<19:
p=p*c
c=c+3
print('Product of first six multiples of 3 is',p)
OUTPUT
Product of first six multiples of 3 is 524880

#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

#9.WAP TO ACCEPT ANY NUMBER AND CHECK WHETHER IT IS EVEN OR ODD


INPUT
n=int(input('Enter a number:'))
if n%2==0:
print(n,'is an even number')
else:
print(n,'is an odd number')
OUTPUT
Enter a number:89
89 is an odd number

#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

#14WAP TO PRINT FIRST TEN NATURAL NUMBER


INPUT
for i in range (1,11,1):
print(i)
OUTPUT
1
2
3
4
5
6
7
8
9
10
#15WAP TO PRINT COUNTING BETWEEN 20 AND 30
INPUT
for i in range (21,30,1):
print(i)
OUTPUT
21
22
23
24
25
26
27
28
29
#16WAP TO PRINT FIRST 20 EVEN NUMBER
INPUT
for i in range (2,41,2):
print(i)
OUTPUT
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
#17WAP TO PRINT ANY NUMBER AND GENERATE ITS TABLE
INPUT
n=int(input('Enter any number:'))
for i in range (1,11,1):
print (n,'*',i,'=',n*i)
OUTPUT
Enter any number:10
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100

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

19. Write a program to print first 10 natural numbers.

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

22.Write 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
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

25.Write a program to append numbers to a list and print


it.
**Input**
nums = []
for i in range(5): nums.append(i)
print(nums)
**Output**
[0, 1, 2, 3, 4]

You might also like