0% found this document useful (0 votes)
2 views5 pages

Python Adesh

The document contains a series of Python programs that perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It also includes calculations for the area and perimeter of circles and rectangles, simple interest, and checks for even/odd numbers, voting eligibility, and temperature conversion. Additionally, it features loops to print numbers, even numbers, multiplication tables, and the sum of a range of numbers.

Uploaded by

ahann14706
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 views5 pages

Python Adesh

The document contains a series of Python programs that perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It also includes calculations for the area and perimeter of circles and rectangles, simple interest, and checks for even/odd numbers, voting eligibility, and temperature conversion. Additionally, it features loops to print numbers, even numbers, multiplication tables, and the sum of a range of numbers.

Uploaded by

ahann14706
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

1. Addition of two numbers.

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

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

res = num1 + num2

print("Sum of the numbers: ", res)

2. Subtraction of two numbers.

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

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

res = num1 - num2

print("Result: ", res)

3. Multiplication of two numbers

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

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

res = num1 * num2

print("Result: ", res)

4. Division of two numbers

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

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

res = num1 / num2

print("Result is: ", res)

5. Area of Circle.

radius = float(input("Enter radius of circle: "))

area = 3.1415 * radius * radius


print("Area: ", area)

6. Perimeter of Circle

radius = float(input("Enter radius of circle: "))

perimeter = 2 * 3.146 * radius

print("Perimeter or Circle: ", perimeter)

7. Area of Rectangle

length = float(input("Enter length of the recetangle: "))

width = float(input("Enter width of the recetangle: "))

area = length * width

print("Area: ", area)

8. Perimeter of Rectangle

length = float(input("Enter length of the recetangle: "))

width = float(input("Enter width of the recetangle: "))

peri = 2 * (length + width)

print("Perimeter of rectangle: ", peri)

9. Calculate Simple Interest

principleAmt = float(input("Enter Principle Amount: "))

time = int(input("Enter duration (year): "))

rateOfInterest = float(input("Enter Rate of Interest: "))

sInterest = (principleAmt * time * rateOfInterest) / 100

print("Perimeter of rectangle: ", sInterest)

10. Greater Number out of two numbers.

x = int(input("first number: "))


y = int(input("second number: "))

if x > y:

print("First number is highest")

elif y > x:

print("Second number is highest")

else:

print("they are same")

11. Smaller Number out of two numbers

x = int(input("first number: "))

y = int(input("second number: "))

if x < y:

print("First number is lowest")

elif y < x:

print("Second number is lowest")

else:

print("they are same")

12. Check number is even or odd

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

rem = num % 2

if rem == 0:

print("The number you entered is Even.")

else:

print("The number you entered is Odd.")

13. Check for the person eligible to vote or not

age = int(input("Enter your age in years: "))


if age >= 18:

print("You are eligible to cast vote.")

else:

print("You are not eligible to cast vote.")

14. Conversion of temperature from Fahrenheit to Celsius or vice versa as given in the
following example:

choice = input("Enter 1 for celcius to farenheit and 2 for

farenheit to celcius): ")

if choice == '1':

celsius = float(input("Enter temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print(celsius,"°C is equal to ", fahrenheit, "°F")

elif choice == '2':

fahrenheit = float(input("Enter temperature in Fahrenheit: "))

celsius = (fahrenheit - 32) * 5/9

print(fahrenheit, "°F is equal to ", celsius, "°C")

else:

print("Invalid choice. Please enter 1 or 2.")

For Loop:

1. Program to print numbers from 1 to 10 using for loop.

for cnt in range(1, 11):

print(cnt)

2. Create a program to print even numbers between 1 to 10.

Version 1:

for cnt in range(1, 11):


if cnt % 2 == 0:

print(cnt)

Version 2:

for cnt in range(2, 11, 2):

print(cnt)

3, Create a program to print the table of a number NUM up to 10.

Num = int(input("Enter the number to print its table: "))

for cnt in range(1, 11):

print(cnt * Num)

4. Create a program to print the sum of all the numbers within given range (between n1 to
n2).

n1 = int(input("Enter the starting value: "))

n2 = int(input("Enter the ending value: "))

s=0

for x in range(n1, n2+1):

s=s+x

print("The sum of the values is: ", s)

You might also like