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

AI-Python Codes-IX-2023-24

The document contains various Python code snippets for basic programming tasks such as printing personal information, calculating area and perimeter, finding sums, and creating lists. It includes examples of control structures like loops and conditionals, as well as operations on lists. Additionally, it provides links to resources for further learning on Python content and programming activities.

Uploaded by

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

AI-Python Codes-IX-2023-24

The document contains various Python code snippets for basic programming tasks such as printing personal information, calculating area and perimeter, finding sums, and creating lists. It includes examples of control structures like loops and conditionals, as well as operations on lists. Additionally, it provides links to resources for further learning on Python content and programming activities.

Uploaded by

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

Python Codes

PRINT 1 To print personal information like Name, Father’s Name, Class, School Name.

# To print personal information


name = input(“enter name: ”)
fname = input(“enter father name: ”)
cls = input(“enter class: ” )
school_name = input(“enter school name: ”)
print(“name: ”, name)
print(“father name: ”, fname)
print(“class: ”, cls)
print(“school name: ”, school_name)

2. To print the following patterns using multiple print commands-

print(“*”)
print(“* *”)
print(“* * *”)
print(“* * * *”)
print(“* * * * *”)

print(“* * * * *”)
print(“* * * *”)
print(“* * *”)
print(“* *”)
print(“* ”)

3. Write python code to find square of number.


Ans
num = float(input("enter your number = "))
square = num*num
print(“square of number =”, square)

4. To find the sum of two numbers 15 and 20.


num1 = int(input(“Enter the 1st number”))
num2 = int(input(“Enter the 2nd number”))
sum = num1+num2
print(“The sum of two numbers is”, sum)
5. To convert length given in kilometers into meters.
length =int(input(“Enter the length”))
result = length * 1000
print(“Length in Meter =”, result)
6. To print the table of 5 up to five terms.
print (5 * 1)
print (5 * 2)
print (5 * 3)
print (5 * 4)
print (5 * 5)

7. To calculate Simple Interest if the principle_amount = 2000


rate_of_interest =4.5 time = 10
# Program to calculate simple interest
p= 2000
r=4.5
t=10
interest=(p*r*t)/100
print(“Simple Interest=”,interest)
8. To calculate Area and Perimeter of a rectangle.
length = int(input(“enter length = “))
breadth = int(input(“enter breadth = “))
area=length* breadth
perimeter=2*( length+ breadth)
print("Area:",area)
print("Perimeter:",perimeter)

9. To calculate Area of a triangle with Base and Height


l=int(input("length"))
b=int(input("breadth"))
area=l*b*0.5
perimeter=2*(l+b)
print("area:",area)
print("perimeter:",perimeter)
10. To calculating average marks of 3 subjects.
# To calculate average of three subjects
e=int(input("English"))
m=int(input("Maths"))
s=int(input("Science"))
t=e+m+s
avg=t/3
print("Average:",avg)

11. To calculate discounted amount with discount %.


# To calculate discounted amount
amt=int(input("amount"))
d=int(input("discount"))
discount=amt*d/100
pay_amt=amt-discount
print("Discounted Amount", discount)
print("Payable Amount",pay_amt)

12. To calculate Surface Area and Volume of a Cuboid


# To calculate surface Area and volume of a Cuboid
l=int(input("Length"))
b=int(input("breath"))
h=int(input("Height"))
s_area=2*(l*b+b*h+h*l)
v=l*b*h
print("Surface Area",s_area)
print("Volume:",v)

• Create a list in Python of children selected for science quiz with following names-
LIST Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
○ Print the whole list
○ Delete the name “Vikram” from the list
○ Add the name “Jay” at the end
○ Remove the item which is at the second position.
n=["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
print(n)
n.pop(2)
n.append("jay")
print(n)
n.pop(2)
print(n)
• Create a list num=[23,12,5,9,65,44]
○ Print the length of the list
○ Print the elements from second to fourth position using positiveindexing
○ Print the elements from position third to fifth using negative indexing
num=[23,12,5,9,65,44]
print(num)
print(len(num))

print(num[2:5:1])

print(num[-2:-5:-1])

• Create a list of first 10 even numbers, add 1 to each list item and print the final list.
• Create a list List_1=[10,20,30,40]. Add the elements [14,15,12] using extend function.
• Now sort the final list in ascending order and print it.
even = [2,4,6,8,10,12,14,16,18,20]
value=1
list2=[]
for i in even:
list2.append(i+value)
print("Final List: ",list2)

List_1=[10,20,30,40]
List_1.extend([14,15,12] )
print(List_1)

List_1.sort()
print(List_1)
• Program to check if a person can vote
IF, age = int(input("enter your age ="))
FOR, if age>=18:
print("you are eligible for vote")
WHILE
else:
print("you are not eligible for vote")

• To check the grade of a student


marks= int(input("enter your marks ="))
if marks>=90:
print("Your Grade is A+")
elif marks>=75:
print("Your Grade is A")
elif marks>=65:
print("Your Grade is B+")
elif marks>=50:
print("Your Grade is B")
else:
print("Work hard")

• Input a number and check if the number is positive, negative or zero and display
an appropriate message
num = int(input("enter a number ="))
if num>0:
print("Number is positive")
elif num==0:
print("number is zero")
else:
print("number is negative")
• To print first 10 natural numbers
for i in range(1,11,1):
print(i)

• To print first 10 even numbers


for i in range(2,21,2):
print(i)

• To print odd numbers from 1 to n


n=int(input("enter limit "))
for i in range(1,n,2):
print(i)

To print sum of first 10 natural numbers
sum=0
for i in range(1,11,1):
sum=sum+i
print(sum)

• Program to find the sum of all numbers stored in a list


total = 0
list1 = [11, 5, 17, 18, 23]
for i in range(0, len(list1)):
total = total + list1[i]
print("Sum of all elements in given list: ", total)
• Python Content Manual:
Import https://cbseacademic.nic.in/web_material/Curriculum21/publication/secondary/Python_Co
ntent_Manual.pdf
ant
• Programs of For and While loops:
Links http://bit.ly/loops_jupyter
• Activities links:
https://bit.ly/40uovYK

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy