0% found this document useful (0 votes)
1 views3 pages

GR 10 Python Programs Term1

Uploaded by

raghunandans7511
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)
1 views3 pages

GR 10 Python Programs Term1

Uploaded by

raghunandans7511
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

GRD PUBLIC SCHOOL, COIMBATORE.

GRADE X – PYTHON PROGRAMS


1. Python Program to Swap Two Numbers.
num1 = int( input("Please Enter Value for Number1: "))
num2 = int( input("Please Enter Value for Number2: "))

temp = num1
num1 = num2
num2 = temp

print ("The Value of Number1 After Swapping: ", num1)


print ("The Value of Number2 After Swapping: ", num2)

2. Python Program to calculate the Area and Perimeter of a Rectangle.


length=float(input("Enter the Length of the Rectangle:"))
breadth=float(input("Enter the Breadth of the Rectangle:"))

area = length * breadth


perimeter = 2 * (length + breadth)

print("The Area of the Rectangle = ",area)


print("The Perimeter of the Rectangle = ",perimeter)

3. Python Program to find the Largest Among Three Numbers.


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)

4. Python Program to make a Simple Calculator.


def add(num1, num2):
return num1+num2
def subtract(num1, num2):
return num1-num2
def multiply(num1, num2):
return num1*num2
def divide(num1, num2):
return num1/num2
print("Please Select Operations - \n" \
"[Link] \n" \
"[Link] \n" \
"[Link] \n" \
"[Link] \n")

select = int(input("Select Operations from 1,2,3,4:"))


n1 = int(input("Enter the first number:"))
n2 = int(input("Enter the second number:"))

if select == 1:
print(n1,"+",n2,"=",add(n1,n2))
elif select == 2:
print(n1,"-",n2,"=",subtract(n1,n2))
elif select == 3:
print(n1,"*",n2,"=",multiply(n1,n2))
elif select == 4:
print(n1,"/",n2,"=",divide(n1,n2))
else:
print("Invalid Input")

5. Python Program to display the Multiplication Table.


num = int(input("Enter the number for which the Multiplication Table is to be displayed:"))
a=int(input("Enter the Starting Range Value:"))
b=int(input("Enter the Ending Range Value:"))
for i in range(a, b+1):
print(num, "x", i, "=", num*i)

6. Python Program to find the Sum of Digits in a Number.


n=int(input("Enter a Number:"))
tot=0

while(n>0):
dig = n % 10
tot = tot+dig
n = n // 10

print("The Sum of Digits is:",tot)

7. Python Program to display the Fibonacci Sequence upto n-th term.


terms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0

if terms <= 0:
print("Please enter a positive integer")
elif terms == 1:
print("Fibonacci Sequence upto",terms,"is:")
print(n1)

else:
print("Fibonacci Sequence:")
while count < terms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count = count+1

8. Python Program to display all the prime numbers within a specified interval.
lower = int(input("Enter the Starting Range:"))
upper = int(input("Enter the Ending Range:"))

print("Prime Numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):


if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)

You might also like