We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
UNIT:
4#Parts of Python Progranming Language
List and explain the purpose of three Python keywords.
help("keywords”)
Here is a list of the Python keywords. Enter any keyword to get more help.
False class from or
None continue global pass
True def if raise
and del import returr
as elif in try
assert else is while
async except Lambda with
await finally nonlocal yiele
break for not
def: Purpose: The def keyword is used to define a function in Python. Explanation: When you
want to create a reusable block of code that performs a specific task, you define a function
using the def keyword. Functions help in organizing code, promoting reusability, and improving
maintainability
if, elif, else:
Purpose: These keywords are used for conditional branching in Python. Explanation: Conditional
statements allow the execution of different code blocks based on whether a specified condition
evaluates to Tue or False,
for.
Purpose: The for keyword is used for looping and iterating over a sequence (such as a lst, tuple,
string, or range). Explanation: A for loop is used when you want to iterate over a sequence of
elements, executing a block of code for each element in the sequence
# Variables, Operators, and Data Types:
‘Perform operations using arithmetic operators (+, -, *, /) on the integer and float
variables and display the results.
azint(input("enter a nunber "))
beint(input ("enter a nunber"))
A= atb
S = (a-b)
P = (a*b)
D = (a/b)
print (A)
print (S)
print (P)
print (0)In
enter a number 3¢
enter a number2@
5e
18
60@
LS
#float variables
a=float(input("enter a number "))
b=float(input("enter a nunber"))
A= arb
S = (a-b)
P= (a%b)
D = (a/b)
print(a)
print(s)
print(P)
print(D)
enter a number 0.
enter a numberd.7
1.2
-0.19999999999999996
0.35
0.7142857142857143
Indentation and Statements:
aurite a Python script with conditional statements (if, elif, else) to check if a give
number is positive, negative, or zero
nt (input ("enter a number*))
if ar:
print(a,"is positive")
elif a=-0:
print(a,"is zero")
els
print(a,"is negative")
enter a number-24
-24 is negative
#UNIT:2
astrings and Lists
‘#Basic String Operations:
Create a string variable containing your full. name.
nane="ahalya reddy”
print(nane)
ahalya reddy
Use indexing to print the Last character of your name.
name="ahalya reddy"
print(name[-1])
y
Use the split() method to split the string into words and store them in a List. Then
athe words with a hyphen (-) and print the result.
name="ahalya reddy"
namei=nane. split ()print(name2)
ahalya-reddy
aUNIT:3
aDictionaries
Creating a Dictionary:
aCreate a dictionary naned “student_info” with the following key-value pairs: “name,
student_info={"name":"ahalya reddy”, “age":"20", “grade":"a", “city":"anantapur"}
print (student_info)
{‘name': ‘ahalya reddy’, ‘age’: ‘28, ‘grade’: ‘a’, ‘city’: ‘anantapur’)
#Access and print the value associated with the "age" key in the “student_info"dictior
student_info={"name":"ahalya reddy", “age":"20", “grade”: "a", "city": "anantapur"}
print(student_info["age"])
28
‘apart2: Tuples
Create a tuple named “months” with the names of the twelve months of the year.
months=("january","febrauary","narch”,"april”,"may", "june", "july", "august, "septenber’
print (months)
(‘January', ‘febrauary', ‘march’, ‘april’, ‘may’, ‘june’, "july', ‘august', ‘septenbe
*", ‘october’, ‘novenber’, ‘decenber*
#80sic Tuple Operations:
# Print the Length of the "months" tuple.
months=("january","febrauary","narch","april","may", "june", "july", "august", "septenber’
print(months[5])
june