Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python_Program_for_grade_9_.docx

The document provides a comprehensive overview of various Python programs demonstrating data types, arithmetic operations, and control flow structures. It includes examples for calculating simple interest, temperature conversion, area of a triangle, and determining number properties (positive/negative, odd/even). Additionally, it covers grade calculation based on marks, color identification using VIBGYOR, and list manipulation methods.

Uploaded by

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

Python_Program_for_grade_9_.docx

The document provides a comprehensive overview of various Python programs demonstrating data types, arithmetic operations, and control flow structures. It includes examples for calculating simple interest, temperature conversion, area of a triangle, and determining number properties (positive/negative, odd/even). Additionally, it covers grade calculation based on marks, color identification using VIBGYOR, and list manipulation methods.

Uploaded by

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

Program to understand python data types.

#Data Types and operators (Exponent, modulus and floor division)

a=10 #int

b=22.7 #float

c="Computer" #str

d=1+5j #complex

e=[10,"Ajay",78] #list

f=(15,"Hi",89.9) #tuple

g={1,2,3,4,5} #set

h={'HTML':'Hyper Text Markup Language','CSS':'Cascading Style Sheet'} #dictionary

print(type(a))#type function gives data type of the variable

print(type(b))

print(type(c))

print(type(d))

print(type(e))

print(type(f))

print(type(g))

print(type(h))

print("The sum is\t",a+b)#\t -Gives one tab in the output

print("The difference is\n",a-b)#\n - Prints the value in new line

print("Exponent",4**3)#** gives exponent of the number

print("Floor Division",25//10)#//(Floor Division)-Gives integer as answer

print("Remainder using modulus operator",27%2)#%(Modulus)-Gives remainder

Program to find Simple Interest

P=float(input("Enter the principle:"))

R=float(input("Enter the Rate:"))

T=float(input("Enter the period:"))

SI=(P*R*T)/100

print("The simple interest is",SI)

Program to convert Celsius to Fahrenheit


#Convert Celsius to Fahrenheit-

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

F=(C*1.8)+32

print("The temperature in Fahrenheit is:",F)

Program to Convert Fahrenheit to Celsius

#Convert Fahrenheit to Celsius

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

C=(F-32)*(5/9)

print("The temperature in Celsius is:",C)

Program to find Area of the traingle

#Area of triangle

base=float(input("Enter the base of the triangle:"))

height=float(input("Enter the height of the triangle:"))

area=0.5*base*height

print("The area of the triangle is",area)

Program to find whether number is positive or negative using simple if.

#program to check whether entered number is positive, negative or zero

num=input("Enter any number:")

num=int(num)

if num>0:

print("Positive")

if num<0:

print("Negative")

if num==0:

print("Zero")

Program to find whether number is odd or even

#program to check whether entered number is odd or even

x=input("Enter any number:")

x=int(x)

if x%2==0:
print("Even")

else:

print("odd")

Program to check whether a person is eligible to vote or not.

#program to check whether a person is eligible to vote or not

age=input("Enter Your age:")

age=int(age)

if age>=18:

print("You are eligible to vote")

else:

print("Sorry, you can’t vote.")

Program to display day name as per the day number using if.... elif

#program to display day name as per the number of day entered

day=int(input("Enter the number of day between 1-7:"))

if day==1:

print("Monday")

elif day==2:

print("Tuesday")

elif day==3:

print("Wednesday")

elif day==4:

print("Thursday")

elif day==5:

print("Friday")

elif day==6:

print("Saturday")

elif day==7:

print("Sunday")
else:

print("Invalid Input")

Program to find percentage and the grades as per the marks entered.

#Logical and using if elif to display grades as per percentage

sub1=float(input("Enter Maths marks:"))

sub2=float(input("Enter Science marks:"))

sub3=float(input("Enter English marks:"))

sub4=float(input("Enter Hindi marks:"))

sub5=float(input("Enter SSC marks:"))

total=sub1+sub2+sub3+sub4+sub5

p=total/5

if p>=90 and p<=100:

print("You scored A+")

elif p>=80 and p<90:

print("You scored A")

elif p>=70 and p<80:

print("You scored B+")

elif p>=60 and p<70:

print("You scored B")

elif p>=50 and p<60:

print("You scored C+")

elif p>=40 and p<50:

print("You scored C")

else:

print("Failed")

Program to display colour name as per the day entered using if...elif

#Logical or with if....elif to display colour name as per VIBGYOR

ch=input("Enter any character for VIBGYOR:")

if ch=='v' or ch=='V':

print("Violet")

elif ch=='i' or ch=='I':


print("Indigo")

elif ch=='b' or ch=='B':

print("Blue")

elif ch=='g' or ch=='G':

print("Green")

elif ch=='y' or ch=='Y':

print("Yellow")

elif ch=='o' or ch=='O':

print("Orange")

elif ch=='r' or ch=='R':

print("Red")

else:

print("Invalid Input")

Program to find middle number among 3

#program to find middle number among 3

a = float(input("Input first number: "))

b = float(input("Input second number: "))

c = float(input("Input third number: "))

# Check if 'a' is greater than 'b'

if a > b:

if a < c:

median = a

elif b > c:

median = b

else:

median = c

else:

if a > c:

median = a
elif b < c:

median = b

else:

median = c

print("The median is", median)

Program to use list and its methods in python

fruits = ['apple', 'banana', 'cherry']


print(fruits)
fruits.append("orange")
print(fruits)
x = fruits.copy()
print(x[1:2])
a = fruits.count("cherry")
print(a)
points = [1, 4, 2, 9, 7, 8, 9, 3, 1]
print(points)
points.clear()
print(points)
cars = ['Ford', 'BMW', 'Volvo']
print(cars)
fruits.extend(cars)
print(fruits)
a = fruits.index("cherry")
print(a)
fruits.insert(1, "water melon")
print(fruits)
fruits.pop(1)
print(fruits)
fruits.remove("banana")
print(fruits)
fruits.reverse()
print(fruits)
cars.sort()
print(cars)
fruits.sort(reverse=True)
print(fruits)

You might also like