[go: up one dir, main page]

0% found this document useful (0 votes)
8 views6 pages

Artificial Intelligence - 05-FEB-2024 - jbGa5opMefA

This document contains a series of Python programs demonstrating the use of the print function, variable assignments, data types, arithmetic operators, and list operations. It includes examples of user input, conditional statements, and basic calculations. Each program is designed to illustrate fundamental programming concepts in Python.

Uploaded by

desaishreemayi
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)
8 views6 pages

Artificial Intelligence - 05-FEB-2024 - jbGa5opMefA

This document contains a series of Python programs demonstrating the use of the print function, variable assignments, data types, arithmetic operators, and list operations. It includes examples of user input, conditional statements, and basic calculations. Each program is designed to illustrate fundamental programming concepts in Python.

Uploaded by

desaishreemayi
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
You are on page 1/ 6

CLASS 09 PYTHON PROGRAMS

print () Function
Program 1: Print your name of the screen using print () function.
print (“Nidhi Trivedi”)
Program 2: Assign a value to a variable and show that value using print () function.
a=25
print(a)
Program 3: Show the use of print () function with two & three objects.
print ("Python is fun.")
a=5
# Two objects are passed
print ("a =", a)
b=a
# Three objects are passed
print ('a =', a, '= b')
Program 4: Print the name of five countries using print () function.
print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")
Variables
Program 5: Assign the same value to several variables simultaneously.
a = b = c = 300
print(a, b, c)
Program 6: Assign different values to several variables simultaneously.
a,b,c = 300,444,500
print (a, b, c)

1
Program 7: Assigned a value of one type and then later re-assigned a value of a different type.
var = 23.5
print(var)
var = "Now I'm a string"
print(var)
Program 8: Assign different types of data to variables.
#An integer assignment
age = 45
# A floating point
salary = 1456.8
# A string
name = "John"
print(age)
print(salary)
print(name)
Data Types
Program 9: Print data type of the values assigned to a variable.
a=5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = ‘Nidhi’
print(a, "is of type", type(a))
Arithmetic Operators
Program 10: Print simple calculator on the screen.
x=int(input(“Enter First number:”))
y=int(input(“Enter Second number:”))
print("The addition of ",x,"+",y,"=",x+y)
print("The subtraction of ",x,"-",y,"=",x-y)
print("The multiplication of ",x,"*",y,"=",x*y)
print("The division of ",x,"/",y,"=",x/y)
print("The reminder of ",x,"%",y,"=",x%y)

2
print("The floor division of ",x,"//",y,"=",x//y)
print("The exponent of ",x,"**",y,"=",x**y)

More on print () and input () functions


Program 11: Take two strings from the user and join (Concatenate) both the strings and display
the answer on the screen.
x=str(input(“Enter your name:”))
y=str(input(“Enter your surname”))
ans= x + y
print(“My name is: ”, ans)
Program 12: Take a string and a number from the user and print that string on the screen
according to the given number.
x=str(input(“Enter your name:”))
y=int(input(“How many times you want to print your name on the screen please enter the number
for the same:”))
ans= x * y
print(ans)
LIST & LIST OPERATIONS
Program 13: Show the use of positive indexing on the list in python.
list1=[12,34,56,"nidhi","trivedi",45]
print(list1[0])
print(list1[1])
print(list1[2])
print(list1[3])
print(list1[4])
print(list1[5])
Program 14: Show the use of negative indexing on the list in python.
list1=[12,34,56,"nidhi","trivedi",45]
print(list1[-1])
print(list1[-2])
print(list1[-3])
print(list1[-4])

3
print(list1[-5])
print(list1[-6])
#Program 15: Create a program to show the use of range (slicing) in the list.
list1=[1,3,"Apple","Samsung","oppo"]
print(list1[2:4])
print(list1[-4:-2])
#Program 16 Create a program to change the list item.
list1=["Cat","dog","Apple","Samsung","oppo"]
print(list1)
list1[2]="banana"
print(list1)
list1[-2]="Vivo"
print(list1)
#Program 17: Find out the length of given list.
list1=["Cat","dog","Apple","Samsung","oppo"]
len(list1)
#Program 18: Append a new item in a list.
list1=["Cat","dog","Apple","Samsung","oppo"]
print(list1)
list1.append("nokia")
print(list1)
#Program 19: Insert new data item in a list at a particular position.
list1=["Cat","dog","Apple","Samsung","oppo"]
print(list1)
list1.insert(2,"Monkey")
print(list1)
#Program 20: Delete a data item in a list at a particular position.
list1=["Cat","dog","Apple","Samsung","oppo"]
print(list1)
list1.pop(2)
print(list1)

4
#Program 21: Delete the list.
list1=["Cat","dog","Apple","Samsung","oppo"]
print(list1)
del(list1)
print(list1)
#Program 22: Show the use of simple if, elif and else.
a=int(input("Enter the number"))
b=int(input("Enter the number"))
if a>b:
print(a,"is grater than",b)
elif a<b:
print(a,"is less than",b)
else:
print(a,"is equals to",b)
#Program 23: Create a program to show whether the student got distinction, first class , second
class or fail on the basis of percentage entered by him/her.
per=int(input("Enter the percentage:"))
if per>=70 and per<=100:
print("You have got distinction")
elif per>=60 and per<70:
print("You have got first class")
elif per>=50 and per<60:
print("You have got second class")
else:
print("You are fail")
#Program 24: Take three numbers as input from the user and find out its sum and product.
no1=int(input(“Enter number 1:”))
no2=int(input(“Enter number 2:”))
no3=int(input(“Enter number 3:”))
print(“The sum of all three numbers is :”,no1+no2+no3)
print(“The product of all three numbers is :”,no1*no2*no3)

5
#Program 25: Write a program to convert kilometers to miles.
km=float(input(“Enter kilometers to convert in miles:”))
const=0.621
miles= km * const
print(“Given kilometer”,km,”in miles are”,miles)

You might also like