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

Python Program

The document outlines 5 Python programs: 1) adding two numbers, 2) checking if a number is even or odd, 3) finding the largest of three numbers, 4) generating a multiplication table, 5) calculating simple interest. Each program is demonstrated with input values and output results.

Uploaded by

kkurablossom143
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)
16 views

Python Program

The document outlines 5 Python programs: 1) adding two numbers, 2) checking if a number is even or odd, 3) finding the largest of three numbers, 4) generating a multiplication table, 5) calculating simple interest. Each program is demonstrated with input values and output results.

Uploaded by

kkurablossom143
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/ 5

PYTHON PROGRAMS

PROGRAM NUMBER: 1

Add any two numbers.

INPUT
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
num1 = float(num1)
num2 = float(num2)
sum = num1 + num2
print("The sum of {0} and {1} is {2}".format(num1, num2, sum))

OUTPUT
Enter first number: 3
Enter second number: 4
The sum of 3 and 4 is 7
PYTHON PROGRAMS
PROGRAM NUMBER: 2

Check if a Number is Even or Odd

INPUT

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


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

OUTPUT

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


if num 2 == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
PYTHON PROGRAMS

PROGRAM NUMBER: 3

Find the Largest Among Three Numbers

INPUT
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)

OUTPUT

Enter first number: 3


Enter second number: 6
Enter third number: 2
The largest number is 6
PYTHON PROGRAMS
PYTHON PROGRAM: 4

Generate a Multiplication Table

INPUT

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


for i in range(1, 11):
print(num, 'x', i, '=', num * i)

OUTPUT
Enter a number: 7
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
PYTHON PROGRAMS
PROGRAM NUMBER: 5

Calculate Simple Interest


INPUT

principal = float(input("Enter the principal amount: "))


rate = float(input("Enter the annual interest rate (in percentage): "))
time = float(input("Enter the time period (in years): "))
simple_interest = (principal * rate * time) / 100
amount = principal + simple_interest
print("Principal Amount: ", principal)
print("Interest Rate: ", rate)
print("Time Period: ", time, " years")
print("Simple Interest: ", simple_interest)
print("Total Amount: ", amount)

OUTPUT

Enter the principal amount: 1000


Enter the annual interest rate (in percentage): 5
Enter the time period (in years): 2
Principal Amount: 1000
Interest Rate: 5
Time Period: 2 years
Simple Interest: 100
Total Amount: 1100

You might also like