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

PROGRAM11

Uploaded by

luvsharma043
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PROGRAM11

Uploaded by

luvsharma043
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PROGRAM-11

Check whether the number is multiple of 15

1. num = int(input("Enter a number: "))


2. if (num % 2) == 0:
3. print("{0} is Even".format(num))
4. else:
5. print("{0} is Odd".format(num))

Output
 Enter a number: 43
 43 is Odd
PROGRAM-2
To find the sum of five numbers
1.def getSum(n):

2. sum = 0
3. for digit in str(n):
4. sum += int(digit)
5. return sum
6.
7. n = 11111
8. print(getSum(n))

Output
5
PROGRAM-3
To calculate the area and circumference of circle
1. pi = 3.14
2. radius = int(input('Enter the radius of a circle: '))
3. area = pi * radius * radius
4. circumference= 2 * pi * radius
5.
6. print(" Area of a circle: " ,area)
7. print(" Circumference of a circle: %.2f" %circumference)

output
 Enter the radius of a circle: 6
 Area of a circle: 113.03999999999999
 Circumference of a circle: 37.68
Program-4
To check the number is prime or not.

1. num = 42
2.
3. # To take input from the user
4. #num = int(input("Enter a number: "))
5.
6. # define a flag variable
7. flag = False
8.
9. if num == 0 or num == 1:
10. print(num, "is not a prime number")
11. elif num > 1:
12. # check for factors
13. for i in range(2, num):
14. if (num % i) == 0:
15. # if factor is found, set flag to True
16. flag = True
17. # break out of loop
18. break
19. # check if flag is True
20. if flag:
21. print(num, "is not a prime number")
22. else:
23. print(num, "is a prime number")

output
 42 is not a prime number

Program 5
To check the year is a leap year.
1. year = 3690
2.
3. # To get year (integer input) from the user
4. # year = int(input("Enter a year: "))
5.
6. # divided by 100 means century year (ending with 00)
7. # century year divided by 400 is leap year
8. If (year % 400 == 0) and (year % 100 == 0):
9. print("{0} is a leap year".format(year))
10.
11. # not divided by 100 means not a century year
12. # year divided by 4 is a leap year
13. elif (year % 4 ==0) and (year % 100 != 0):
14. print("{0} is a leap year".format(year))
15.
16. # if not divided by both 400 (century year) and 4 (not century y
ear)
17. # year is not leap year
18. else:
19. print("{0} is not a leap year".format(year))

output
 3690 is not a leap year.
Program-6
To print the highest number from
three numbers.
1. num1 = 10
2. num2 = 14
3. num3 = 12
4.
5. # uncomment following lines to take three numbers
from user
6. #num1 = float(input("Enter first number: "))
7. #num2 = float(input("Enter second number: "))
8. #num3 = float(input("Enter third number: "))
9.
10. if (num1 >= num2) and (num1 >= num3):
11. largest = num1
12. elif (num2 >= num1) and (num2 >= num3):
13. largest = num2
14. else:
15. largest = num3
16.
17. print("The largest number is", largest)

Output
 The largest number is 14
Program-7
To print the table of any number.
1. num = 12
2.
3. # To take input from the user
4. # num = int(input("Display multiplication table of? "))
5.
6. # Iterate 10 times from i = 1 to 10
7. for i in range(1, 11):
8. print(num, 'x', i, '=', num*i)

output
 12 x 1 = 12
 12 x 2 = 24
 12 x 3 = 36
 12 x 4 = 48
 12 x 5 = 60
 12 x 6 = 72
 12 x 7 = 84
 12 x 8 = 96
 12 x 9 = 108
 12 x 10 = 120
Program-8
To print the sum and multiplication of
three numbers.
1. num1=int(input("enter the first number"))
2.
3. num2=int(input("enter the second number"))
4.
5. num3=int(input("enter the third number"))
6.
7. sum= num1+num2+num3
8.
9. product= num1*num2*num3
10.
11. print("the sum of three number is",sum)
12.
13. print("the product of three number is",sum)

output
 enter the first number1
 enter the second number2
 enter the third number3
 the sum of three number is 6
 the product of three number is 6
Program-9
To find the area and perimeter of a
rectangle.
1. # Area & Perimeter of Rectangle
2.
3. # Reading length from user
4. length = float(input("Enter length of the rectangle: "))
5.
6. # Reading breadth from user
7. breadth = float(input("Enter breadth of the rectangle: "))
8.
9. # Calculating area
10. area = length * breadth
11.
12. # Calculating perimeter
13. perimeter = 2 * (length * breadth)
14.
15. # Displaying results
16. print("Area of rectangle = ", area)
17. print("Perimeter of rectangle = ", perimeter)

output
 Enter length of the rectangle: 2
 Enter breadth of the rectangle: 3
 Area of rectangle = 6
 Perimeter of rectangle = 12
Program-10
To check the number is multiple of
five or not.
(only for positive numbers)
1. num = int(input("enter a positive number:"))
2. if num > 0:
3. if num %5==0:
4. print(num,"is a multiple of 5.")
5.
6. else:
7. print(num,"is not a multiple of 5.")

output
 enter a positive number:15
 15 is a multiple of 5.

You might also like