Basics of Python (SEC-I) B.SC (CS) - II Yr - III SEM
Basics of Python (SEC-I) B.SC (CS) - II Yr - III SEM
D.Ankitha
Roll no :107222467016
BSC-MSCs-2A
In python variables have two types
they are:
•Local variables
•Global variables
Local variables:
•A local variables is created inside a function and
cannot be accessed by statements that are out
side the function .
Out put:
Total : 12
Global variables:
Variables that are Example:
global_variable = 42
declared outside the def my _function():
function are known as Print(“ Inside the function: global _variable =”,
global _variable)
global variables. You can
Print (“outside the function: global _variable =”,
access global variables in global _variable)
COMPARING STRINGS:-
ASWINI ARAVIND
B.SC(MSCS2A)
107222467005
ASWINI
COMPARING STRINGS PROGRAM:-
Topic:-
FILES AND ITS TYPES
S.NANDA KESHAVA REDDY
107222467081
FILES:-
A file is some information or data which stays in the computer storage devices. You
already know about different kinds of file , like your music files, video files, text
files. Python gives you easy ways to manipulate these files. Generally we divide
files in two categories, text file and binary file.
•when a program needs to save data for later use,it writes the data in the file.
• A text file contains data that has been encoded as text, using a scheme such as ASCCI
(Or) Unicode
• Text files: In this type of file, Each line of text is terminated with a special character
called EOL (End of Line), which is the new line character ('\n') in python by default.
•A running total is sum of numbers that accumulates with each iteration of a loop.
SECTION: IIB
2. User Defined Functions: User can create their own functions based on their
requirements.
print(“Hello”)
Function with Arguments.
1. Function can also have arguments.
2. An argument is a value that is accepted by a function.
3. By default, a function must be called with the correct number of
arguments. Meaning that if your function expects 2 arguments,
you have to call the function with 2 arguments, not more, and
not less.
SYNTAX:
NOTE: The ‘return’ statement denotes that function has ended. Any
statements after return statement are not executed.
Function Call
● When the function is called the control program goes to the
function definition.
● All codes inside the function are executed.
● The control of the program jumps to the next statement after the
function call.
def func_name():
#function body
return
func_name() Function call
Examples:
Function without arguments: Function with arguments:
code: code:
#creating a func called greet #creating a func called greet
def greet(): def greet(a):
print(“hey”) print(a)
return return
#calling func #calling func
greet() greet(hey)
Output: Output:
hey hey
THANK YOU
DATA TYPES IN
PYTHON
Name- J.Amulya Mahathi
Class- BSC MSCs 2B
Roll Number- 107222467073
What is Data Type?
statement
statement
etc.
.
WHILE LOOP
● While loop is a condition-controlled
loop.
● It causes a statement or a set of
statements to repeat as long as a
condition is true.
● The while loop is known as a
pretest loop, which means it tests
its condition before performing an
iteration.
● Syntax:
while condition:
statement
statement
etc.
NESTED LOOPS
● Nested loop means loop inside
loop.
● In the nested loop, the number
of iterations will be equal to the
number of iterations in the outer
loop multiplied by the iterations
in the inner loop.
● Syntax:
Outer_loop Expression:
Inner_loop Expression:
Statement inside inner_loop
THANK YOU!!!
OPERATORS
IN PYTHON
P.V.P.L. HARIKA
10722467093
BSC(MSCs)-2B
OPERATORS- INTRO
❏ Operators are used to perform operations on variables and values.
These variables and values can be called as “Operands”.
❏ There are different types of operators:
● Arithmetic Operators
● Assignment Operators
● Relational Operators
● Logical Operators
● Bitwise Operators
● Conditional Operators
● Special Operators
Arithmetic Examples performing Arithmetic
Operations
Operators
❖ These operators are used to perform
mathematical operations.
Assignment Examples performing Assignment
Operators
Operators
❖ Assignment operators are used
to assign the values.
Relational Examples performing Relational
Operators
Operators
❖ These are relational Operators.
Logical Examples performing Logical
Operators
Operators
❖ Logical Operators are used to
combine conditional statements.
Bitwise Examples performing Bitwise
operations
Operators
❖ Bitwise operators are used to compare
binary numbers and they perform
bit-by-bit operations.
Conditional Example performing conditional
operators
Operators
❖ Also called as “Ternary
Operators”
Special
Examples performing special
Operators operators
Bhubaneswori Bal
107222467067
MSCs 2b
What is a Decision making statement?
● If statements
● If-else statements
● If elif else statement
● Nested decision structures
The If statement
The if statement contains a boolean expression
using which the data is compared and a decision is
made based on the result of the comparison.
Syntax:
If(condition)
Statement
else:
statement
If elif else statement
The elif statement allows you to check multiple expressions
for TRUE and execute a block of code as soon as one of the
conditions evaluates to TRUE. There can be an arbitrary
number of elif statements following an if.
Syntax
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression 3:
statement(s)
else:
statement(s)
Nested Decision Structures
To test more than one condition, a decision structure can
be nested inside another decision structure. It can be a
combination of simple if, if-else and elif statements.
THANK YOU!
PROCESSING RECORDS
Shraddha Chakraborty
MSCs 2B
Roll no: 107222467070
Concept:
❖ The data that is stored in a file is frequently organized
in records.
❖ A record is a complete set of data about an item, and a
field is an individual piece of data within a record.
❖ Suppose we want to store data about employees in a
file. The file will contain a record for each employee.
Each record will be a collection of fields, such as name,
ID number, and department.
TYPE CONVERSIONS
Name:M.Vaishnavi
Class:BSC Mscs -2A
Roll no :107222467036
Type conversions
Type conversion is the process of converting data of
one type to another. For example: converting int data
to str.
Name : K . Swetha
Class : BSC MSCs -2A
Roll.no. : 107222467032
What is Variable Scope ?
● Variable scope refers to the region of a program where a
variable is defined and can be accessed. In python, variables can
have two types they are,
● Local Variables
● Global Variables
scope refers to the region of a program where a variable is defined
Local Variables
● Local Variables are declared and defined inside a function. They are
By :
R Srinath Reddy
BSC MSCS 2B
107222467099
In programming, type
conversion is the
types of type
automatic type
conversion
Conversion automatically
converts one data
type to another
without any user
involvement.
Example
x = 10
print("x is of type:",type(x))
y = 10.6
print("y is of type:",type(y)) Output
# int variable
a = 5.9
Output:
# typecast to int
n = int(a)
5
print(n) <class 'int'>
print(type(n))
Thank you !
PROGRAM DEVELOPMENT CYCLE
IN PYTHON
Sarvagna.Dundigalla
Bsc mscs2a
107222467017
Design the Write the Correct syntax
program code errors
Name: K.Sruthi
Class: Bsc MScs 2-A
Roll no:107222467028
VALUE RETURNING FUNCTIONS
● A value-returning function is a function that
returns a value back to the part of the program
that called it.
● We can define a function by using the ʻdefʼ
keyword.
● Python, as well as most other programming
languages, provides a library of prewritten
functions that perform commonly needed tasks .
SYNTAX Example of value returning function
that adds two numbers and returns the
result:
def function_name(parameters):
def add_numbers (a,b):
Statement result=a+b
Statement return result
sum_result=add_numbers(2,4)
Etc.
print(sum_result)
Return expression
Output:
6
A library function viewed as a black box
PARTS OF THE FUNCTION
Discover the Magic of
Python Program
Development Cycle
Explore how planning,coding,testing,documentation,maintenance,and
updates come together in the development cycle of a program. See the
beauty of Python programming through expert eyes.
107222467051
Introduction to Program Development Cycle
- Planning and Analysis
Definition Importance Steps
The program development Planning and analysis are Planning and analysis
cycle is the process of crucial as they set the involve defining the problem,
designing and developing direction for the program determining the program
computer programs. development cycle and specifications,and
define w hat the program is identifying the resources
supposed to do. req uired.
Coding and Implementation
1 Coding
Testing is the process of Debugging is the process of Automation tools like debugging
checking the program's identifying,analyzing,and softw are and unit testing
functionality against expected correcting errors in the program. framew orks help increase
behaviors. efficiency and accuracy during
the testing and debugging
process.
Documentation
1 Description
Documentation is the process of describing the program and how to use it.
2 Types of Documentation
3 Importance
Documentation ensures that others can understand and use the program effectively.
Maintenance and Updates
Maintenance Updating V ersion Control
3 Continuous Learning
107222467058
What are Exceptions?
Exceptions are events that occur during program execution that disrupt the
normal flow. They can be caused by user errors, system failures, or unforeseen
circumstances.
Types of Exceptions
SyntaxError TypeError
An error caused by invalid Python syntax. An error that occurs when an operation is
performed on an object of an inappropriate
type.
ValueError FileNotFoundError
An error that occurs when a function receives An error that occurs when a file or directory is
an argument of the correct type but an not found.
inappropriate value.
How to Handle Exceptions
1 Try-Except blocks
Use specific exception types to catch Avoid using overly complex exception
and handle only the errors you expect. handling logic. Keep it simple, readable,
Avoid using bare except clauses. and maintainable.