0% found this document useful (0 votes)
4 views8 pages

IX AI Python Program List

The document contains a series of Python programs that demonstrate various programming concepts such as calculating the area and perimeter of a rectangle, checking if a number is divisible by 5, determining if a number is a palindrome, summing numbers, printing multiples, calculating factorials, and finding averages. Each program includes input prompts and outputs for user interaction. The examples illustrate the use of loops and conditionals in Python.

Uploaded by

Aryan Sao
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

IX AI Python Program List

The document contains a series of Python programs that demonstrate various programming concepts such as calculating the area and perimeter of a rectangle, checking if a number is divisible by 5, determining if a number is a palindrome, summing numbers, printing multiples, calculating factorials, and finding averages. Each program includes input prompts and outputs for user interaction. The examples illustrate the use of loops and conditionals in Python.

Uploaded by

Aryan Sao
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

6.

#WAP to print area and perimeter of a rectangle


l=12.5
b=10.2

area=l*b

peri=2*(l+b)
print("Area of rectangle is:",area)
print("Perimeter of rectangle:",peri)
9. #WAP to check whether person is senior citizen or not?

10. #WAP to check if the number is divisible by 5 or not


d = int(input("Enter a number: "))

if (d%5 == 0):

print("Number is divisible by 5")


else:

print("Number is not divisible by 5")

Output:

11. #WAP to check number is palindrome or not using while loop

num = int(input("Enter number: "))

temp = num

reverse = 0

while temp > 0:

remainder = temp % 10

reverse = (reverse * 10) + remainder

temp = temp // 10

if num == reverse:

print('Palindrome')

else:

print("Not Palindrome")

Output:

Enter number: 12321

Palindrome

Enter number: 458465

Not Palindrome

12. # WAP to find the sum of the numbers using for loop

nums = (1, 2, 3, 4)

sum_nums = 0
for i in nums:

sum_nums = sum_nums + i

print('Sum of numbers is', sum_nums)

Output:

Sum of numbers is 10

13. #WAP to print multiple of the number using for loop

number = int(input("Enter number: "))

print("The multiples are: ")

for i in range(1,11):

print(number*i, end =" ")

Output:

Enter number: 6

The multiples are:

6 12 18 24 30 36 42 48 54 60

14. # WAP to find the factorial of a number using for loop

# n = int (input ("Enter a number: "))

factorial = 1

for i in range (1, n+1):

factorial = factorial *i

print ("Factorial of the given number is: ", factorial)

Output:

Enter a number: 7

Factorial of the given number is: 5040

15. #WAP to calculate the sum of all the odd numbers within the given range using
for loop

given_range = int(input("Enter the range "))

sum = 0

for i in range(given_range):

# if i is odd, add it

# to the sum variable

if i%2!=0:

sum+=i

print(sum)

Output:

Enter the range 10

25

16. # WAP to check the number is even or odd from a series of numbers using
for loop.

num_list = [1,3,5,6,99,134,55]

for i in num_list:

# if divided by 2, all even number leave a remainder of 0

if i%2==0:

print(i,"is an even number.")

# if remainder is not zero then it's an odd number

else:

print(i,"is an odd number.")

Output:

1 is an odd number.

3 is an odd number.
5 is an odd number.

6 is an even number.

99 is an odd number.

134 is an even number.

55 is an odd number.

17. # WAP to calculate average of the numbers using while loop

num=0

count=0

sum=0

while num>=0:

num = int(input('enter any number …, -1 to exit: '))

if num >= 0:

count = count + 1 # this counts number of inputs

sum = sum + num # this adds input number cumulatively.

avg = sum/count

print('Total numbers: ', count, ', Average: ', avg)

Output:

enter any number .. -1 to exit: 12

enter any number .. -1 to exit: 45

enter any number .. -1 to exit: 44

enter any number .. -1 to exit: 78

enter any number .. -1 to exit: -1

Total numbers: 4 , Average: 44.75

You might also like