Python
Assignment
Name:-
Arav Arya
[Link]:-
ECH25051
Course:-
B.A. Economics Honours
Subject:-
Essentials of Python
Submitted to:-
Monahar Singh
INDEX
[Link] Syntax
[Link] Booleans
3. Python Operators
4. Python Lists and
Tuples
5. Python Dictionary
6. Python Loops
7. Python If…..Else
8. Python Functions
9. Python Combine
Program
10. Python Casting
Platform Used:- Python IDLE
3.14.3
Python Syntax
Input:- Print(“Jai,Hind”)
Output:- Jai,Hind
Input:- Print(“I am Ram”)
Output:- I am Ram
Input:- x= “My name is Arav
Arya.”
y= “I stay in Delhi.”
Print(x+y)
Output:- My name is Arav
Arya. I stay in Delhi.
Python Booleans
Input:- Print(10>2)
Output:- True
Input:- Print(10=2)
Output:-False
Input:- Print(10<2)
Output:-False
Input:- a = 200
b = 33
if b > a:
print("b is greater than a")
else:
print("b is not greater than
a")
Output:-b is not greater than
a
Python Operators
1)Addition and Subtraction
x = 250
y = 100
print(x+y)
print(x-y)
350
150
2)Multiplication and Division
x = 100
y = 20
print(x*y)
print(x/y)
2000
5
3)Floor Division and Modulo
x =17
y=3
print(x//y)
print(x%y)
5
2
4) Comparison Operator
a = 25
b = 50
print(a==b)
print(a!=b)
print(a<b)
False
True
True
5) Logical AND
x = 50
print(x>30 and x<10)
True
6) Logical OR
x = 50
print(x ==50 or x ==0)
True
7) Logical NOT
x = True
print(not x)
False
8) Assignment Operator
x = 100
x +=50
x -=20
print(x)
3000
9)Identity Operators
a =[6,9]
b =[6,9]
c=a
print(a is c)
print(a is b)
True
False
Python Lists and Tuples
1)List
players = [“Max”, “Jay”,
“Ram”]
new_players = [“John”,
“Eve”]
print(all_players)
[‘Max’, ‘Jay’, ‘Ram’, ‘John’,
‘Eve’]
Input:-
scores = [10,20,30,60,90]
[Link]()
highest = scores[-1]
print(highest)
Output:-
90
2) Tuples
Input:-
Players = (10,20,30,45,65)
lowest = min (players)
print(lowest)
Output:- 10
Input:-
greek_letters = (“alpha”,
“beta”, “gamma”)
count = len(greek_letters)
print(count)
Output:-
3
Python Dictionary
Input:-
stock ={“apples”:50,
“oranges”:30}
quantities =
list([Link]())
print(quantities)
Output:-[50,30]
Input:-
employee = {“id”:5, “dept”:
“HR”, “salary”:156155}
labels = list([Link]())
print(labels)
Output:-[‘id’, ‘dept’, ‘salary’]
Python Loops
Input:-
fruits = ["apple", "banana",
"cherry"]
for x in fruits:
print(x)
Output:-
Apple
Banana
cherry
Input:-
for x in "banana":
print(x)
Output:-
b
a
n
a
n
a
Python If…..Else
Input:-
marks = 96
if marks>=90:
print(“Grade:A”)
elif marks>=80:
print(“Grade:B”)
elif marks>=70:
print(“Grade:C”)
else:
print(“Grade:F”)
Output:-
Grade: A
Input:-
year = 2024
if (year%4==0 and year
%100!=0) or
(year%400==0):
print(“Leap Year”)
else:
print(“Not a Leap Year”)
Output:
Leap Year
Input:
stock_count = 2
if stock_count ==0:
print(“Out of Stock”)
elif stock_count<5:
print(“Low Stock:Please
reorder soon”)
else:
print(“Stock levels are
sufficient”)
Output:
Low Stock: Please reorder
soon
Python Functions
Input:-
def area(length,width):
returnlength*width
print(area(39,45))
Output:-
1755
Input:-
def
calculate_interest(p,r,t):
si = (p*r*t)/100
print(si)
calculate_interest(5500,8
,3)
Output:-
1320.0
Input:-
def get_length(text):
return len(text)
print
(get_length(“Somethings
in the way!”))
Output:-
22
Python Combine
Program
Input:-
def check_speed(s):
if s>60:
return “Fast”
else:
return “Safe”
road_data =(“Highway”,
“Route 66”)
cars = [{“car”: “Toyota”,
“speed”:50},{“car”:
“Ferrari”, “speed”,100}]
print( “Road:”,road_data[
0])
for c in cars:
alert =
check_speed(c[“speed”]
print(c[“car”], “;”,alert)
Output:-
Road: Highway
Toyota: Safe
Ferrari: Fast
Input:-
def check_group(age):
else:
return “Kid”
data_info = (“Family
Member”, “2023”)
people = [{“name”,
“Suresh”,
“age”:21},{“name”:
“Rani”,
“age”:6}]
print(“Data:”,data_info[0]
)
for p in people:
group =
check_group(p[“age”])
print(p[“name”],
“is”,group)
Output:-
Data:Family Members
Suresh is Adult
Rani is Kid
Input:-
def
get_reaction(action_force
)
reaction = -action_force
return reaction
push = 250
opposite_push =
get_reaction(push)
print(“Action:”,push)
print(“Reaction:”,
opposite_push)
output:-
Action:250
Reaction: -250