0% found this document useful (0 votes)
100 views128 pages

Basics of Python (SEC-I) B.SC (CS) - II Yr - III SEM

- Numeric types: integers, floating point numbers, complex numbers. Integers are whole numbers like 5 and floats have decimal points like 5.6. - Strings are sequences of characters like "hello". - Lists are ordered collections of objects that can be changed. Lists are written with square brackets like [1,2,3]. - Tuples are like lists but values cannot be changed after creation. Tuples use parentheses like (1,2,3). - Sets are unordered collections with no duplicate elements. Sets use curly braces like {1,2,3}. - Dictionaries associate keys with

Uploaded by

Shadow Monarch
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)
100 views128 pages

Basics of Python (SEC-I) B.SC (CS) - II Yr - III SEM

- Numeric types: integers, floating point numbers, complex numbers. Integers are whole numbers like 5 and floats have decimal points like 5.6. - Strings are sequences of characters like "hello". - Lists are ordered collections of objects that can be changed. Lists are written with square brackets like [1,2,3]. - Tuples are like lists but values cannot be changed after creation. Tuples use parentheses like (1,2,3). - Sets are unordered collections with no duplicate elements. Sets use curly braces like {1,2,3}. - Dictionaries associate keys with

Uploaded by

Shadow Monarch
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/ 128

Instructions to students

➔ Prepare individual ppts max upto 5 slides only


➔ Choose any Topic from UNIT-1 / UNIT-2
➔ Try not to repeat the same concept ppts
➔ Ppts should be unique
➔ Donʼt delete other ppts.if do so disciplinary action will be taken
➔ After ppts preparation,make a slide copy with you
➔ Time for presentation upto 5 min only
➔ Prepare viva well
➔ Donʼt share link with any one.
Please start your presentation from next slide
Variable scope in python

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 .

•Different functions can have local variables


with the same names because the functions
Cannot see each other's local variables.
Example:
Def calculate_sum(a,b):
Result = a + b
Return result
Total = calculate_sum(5,7)
Print (“total:”, total)

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)

python both inside and Out put:


Inside the function: global _variable = 42
outside the function. Outside the function: global _variable = 42
Thank you
TOPIC:-

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.

•File is a collection of information


Types of files:-
1)Text files:-

• 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.

• characters are stored in text files.

• All text information is called text files.

• Files are stored in Harddisk


2)Binary files:-
• The data which has not been converted into a text is called binary files.
• The data that is stored in a binary file is intended only for a program to read.
Example:-
Executable files, compiled programs, SAS and SPSS system files, spreadsheets,
compressed files, and graphic (image) files are all examples of binary files.
TOPIC:-
CALCULATING RUNNING TOTAL
AND
INPUT VALIDATION LOOPS
INTRODUCTION

M.SHESHA KAMALA VASINI


B.SC(MSCS2A)
107222467041
CALCULATING RUNNING TOTAL:-
A running total or rolling total is the summation of a sequence of numbers which is
updated each time a new number is added to the sequence, by adding the value of the
new number to the previous running total. Another term for it is partial sum. The
purposes of a running total are twofold.

•A running total is sum of numbers that accumulates with each iteration of a loop.

•The variable used to keep running total is called an accumulator.


CALCULATING RUNNING TOTAL PROGRAM:-
INPUT VALIDATION LOOPS:-
Use a while loop to iterate until the provided input
value is valid.Check if the input value is valid on
each iteration.An input validation loop is
sometimes called an error trap or error handler.
INPUT VALIDATION LOOPS PROGRAM:-
INTRODUCTION.
NAME: Punna Teena

CLASS: Bsc. MSCs

SECTION: IIB

ROLL NO: 107222467097


FUNCTIONS
WHAT IS A FUNCTION?
1. Functions are pieces of code that are written to perform a
specific task.
2. In Python, functions are declared using the ‘def’ keyword. And
had 4 indentation (space) after declaration.
3. Once a function is declared, it can be called and used whenever
needed. This makes it easy for developers to reuse code and
save time when coding.
SYNTAX:
● def - keyword used to
declare a function
● func_name - any
name given to
def func_name(): function
#function body ● return - returns value
Return from a function it is
optional
func_name()

NOTE: The ‘return’ statement denotes that function has ended.


Any statements after return statement are not executed.
Types of Functions
1. Standard Library Functions: These are in-built functions in Python that are
available to use.

Eg: math, len(), max(), print(), etc,.

2. User Defined Functions: User can create their own functions based on their
requirements.

Eg: def greet():

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:

● def - keyword used to


declare a function
def ● func_name - any
name given to
func_name(arguments): function
#function body ● return - returns value
from a function it is
return optional
func_name(arguments)

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?

In software programming, data type refers to the type of value a


variable has and what type of mathematical, relational or logical
operations can be applied without causing an error.
The data type defines which operations can safely be performed to
create, transform and use the variable in another computation.
Basic Data Types
The various types of data types in python are:-
● Numbers
● String
● List
● Tuples
● Set
● Dictionary
Numeric Data Type
The numeric data type in Python represents the data that has numeric values. A
numeric value can be integer, floating number, complex number. These values are
defined as int, float, complex.

● Integer - This value is represented by int class. It contains positive or negative


whole numbers(without fraction and decimal). Ex: A=-123, B=-125
● Float - This value is represented by float class. It is a real number with floating
point representation. It is specified by decimal point. Ex: A= 12.67
● Complex - Complex number is represented by complex class. Ex: X=1+2j
String Data Type
● Strings are arrays of bytes representing Unicode characters.
● A string is a collection of one or more characters put in single quote,
double quotes.
● In Python, there is no character data type, a character is a string of
length one. It is represented by str class.
List Data Type
● Lists are just like arrays, declared in other languages which is
an ordered collection of data.
● It is very flexible as the items in a list do not need to be of same
type.
● It is most used data type.
● It is created by using [ ] (square brackets).
● Ex - L[20, 20.5, “python”, 2+3j].
Tuple Data Type
● Tuple is an ordered collection of Python objects.
● It is special used data type.
● Values are not changeable. Hence they are immutable.
● It stores different kind of data.
● It is created by using () (paranthesis).
● Ex - t = (20, 20.49, “python”, 2+3j).
Set Data Type
● Set is a collection of unordered sequence.
● It is a special used data type.
● Items in this data type are not in order.
● In set data type we can perform union, intersection, etc operations.
● It is created by using { } (curly braces).
● Ex - s = {5, 2, 3, 1, 4).
Dictionary Data Type
● A Dictionary is a group of unordered collection of key values.
● It is specially used in big data analysis.
● In this data type, data can be accessed by key values.
● It is created by using { } (curly braces).
● It can also be created by built-in function dict().
● Syntax - {key : data}
● Ex - {1:ʼramuʼ , 2:ʼtrinitydcpdlʼ}
Thank You!!
WHAT ARE LOOPS?
● Loops are repetitive control structures used to execute a
block of codes multiple times.
● Loops are fundamental for performing repetitive tasks and
iterating through data structures in python programs.
● There are mainly three types of loops in Python:
1. For Loop
2. While Loop
3. Nested Loop
CONTROL STRUCTURES-
LOOPS
-Sriharshini R
BSc MSCs 2B
107222467098
FOR LOOP
● For loop is a ʻcount controlledʼ loop.
● The program iterates only a specific
number of times.
● Syntax:-

for variable in [value1, value2, etc.]:

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

❖ These are used to compare objects


to check if they are actually the
same object.
Specification Of Operators
THANK YOU
Decision Structures

Bhubaneswori Bal
107222467067
MSCs 2b
What is a Decision making statement?

Decision structures, which are statements that allow a program to


execute different sequences of instructions for different cases, allowing
the program to “choose ” an appropriate course of action.

Types of decision making statements in Python:

● 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.

If the boolean expression evaluates to True, then


the block of statement(s) inside the if statement is
executed. In Python, statements in a block are
uniformly indented after the ":" symbol. If boolean
expression evaluates to False, then the first set of
code after the end of block is executed.
If Else Statement
Along with the if statement, else keyword can also be
optionally used. It provides an alternate block of statements
to be executed if the Boolean expression (in if statement) is
not true.

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.

There are two types of type conversion in Python.

● Implicit Conversion - automatic type conversion


● Explicit Conversion - manual type conversion
Implicit Type Conversion

● It will be done automatically by the python


interpreter
● When an operation is performed on two int
values,the result will be int.
● When an operation is performed on an int
and a float,then the int value will be
converted into float and result will be float.
Note:

We get TypeError, if we try


to add str and int. For
example, '12' + 23. Python is
not able to use Implicit
Conversion in such
conditions.
Python has a solution for
these types of situations
which is known as Explicit
Conversion.
Implicit
Explicit Type Conversion
● In Explicit Type Conversion, users convert the data type
of an object to required data type.

● We use the built-in functions like int(), float(), str(), etc


to perform explicit type conversion.

● This type of conversion is also called typecasting


because the user casts (changes) the data type of the
objects.
Explicit
Thank you!
VARIABLE SCOPE IN PYTHON

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

created when the function is called and destroyed when it completes


execution.
● Local Variables are inaccessible outside of the function.
Example of defining a local Variable :
● In the above example, x is a local
variable defined inside the
my_function() function. It is
accessible only within the
function. When the function is
called, x is assigned the value 10
and printed. If you try to access x
outside of the function, you will
encounter a NameError.
Global Variables
● To define a global variable,you can declare it outside of
any function or at the module level. Global Variables can
be accessed from anywhere within the module.
Example of defining a Global Variable :

● In the above example, x is a


global variable defined
outside of any function. It
can be accessed both inside
and outside of the
my_function() function.
Thank you!
Type Conversions

By :
R Srinath Reddy
BSC MSCS 2B
107222467099
In programming, type
conversion is the

What is type process of converting


data of one type to

Conversion ? another. For example:


converting int data to
str.
There are two Implicit Conversion -

types of type
automatic type
conversion

conversion in Explicit Conversion -


manual type conversion
Python.
In Implicit type
conversion of data
types in Python, the
Implicit Type Python interpreter

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

z=x+y x is of type: <class 'int'>


y is of type: <class 'float'>
print(z) 20.6
print("z is of type:",type(z)) z is of type: <class 'float'>
In Explicit Type Conversion in
Python, the data type is
manually changed by the user
Explicit Type as per their requirement. With
explicit type conversion, there

Conversion is a risk of data loss since we


are forcing an expression to
be changed in some specific
data type.
# Python program to demonstrate
# type Casting

# 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

Correct logic Test the


errors program
Program design consists of the
DESIGN THE steps a programmer should do
PROGRAM before they start coding the
program in a specific language.
After designing the program ,the
WRITE THE CODE programmer begins writing code in
a high-level language such as
Python
CORRECT SYNTAX If the program contains a syntax
error ,or even a simple mistake ,the
ERROR compiler or interpreter will display
an error message indicating what
the error is.
CORRECT LOGIC If the program produces
ERRORS incorrect results ,the
programmer identify and
remove errors from.
Once the code is in an
TEST THE PROGRAM execute form ,it is then
tested to determine
whether any logic error exit
Thank you..!!
VALUE RETURNING
FUNCTIONS

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.

BY R.HEMANTH BABU(B.SC MSCS 2B)

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

Coding is the process of w riting


instructions in a programming language.
Implementation 2
Implementation involves converting
w ritten code into a functional program.
3 Iterative Process

Coding and implementation req uire


constant iteration to ensure that the
program is functioning as expected.
Testing and Debugging

Testing Debugging Automation Tools

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

Types of documentation include user guides,technical documentation,and help files.

3 Importance

Documentation ensures that others can understand and use the program effectively.
Maintenance and Updates
Maintenance Updating V ersion Control

Maintenance involves Updating involves enhancing V ersion control helps


monitoring the program's the program's performance manage updates and
functionality and correcting or features to meet ensures that previous
errors as they arise. changing needs or versions of the program can
preferences. be accessed if needed.
Conclusion
1 Importance 2 Efficiency

Understanding the program The program development


development cycle is crucial cycle ensures efficient use
for creating q uality of resources and helps
programs that meet user developers meet timelines
needs. and budgets.

3 Continuous Learning

The program development cycle is an iterative and ongoing process


that demands continuous learning and improvement.
Exceptions in Python:
Handling Errors
Gracefully
Welcome to our presentation on exceptions in Python! Discover how to handle
errors gracefully in your code, ensuring smooth execution and better user
experience.
by S.KEERTHI (B.SC MSCS 2B)

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

Wrap the code that may raise an


exception in a try block and handle the
The else clause 2 exception in the corresponding except
Include an else clause within the try- block.
except block to specify code that should
be executed only if no exceptions occur. 3 The finally clause

Use the finally clause to specify code


that should be executed regardless of
whether an exception occurred or not.
Useful for cleaning up resources.
Best Practices for U sing Exceptions
in Python
1 Be specific with exceptions 2 Keep exception handling concise

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.

3 D on't ignore exceptions 4 Log exceptions

Ignoring exceptions can lead to Logging exceptions provides valuable


unexpected behavior or even program information for debugging and
crashes. Always handle exceptions troubleshooting. Include relevant
appropriately. details in your logs.
Putting It A ll Together

Write Robust Code Easier D ebugging Collaboration & Efficiency

By understanding exceptions Exception handling helps Effective exception handling


and implementing proper error identify and locate issues in your promotes collaboration among
handling, you can write more code, making debugging faster developers and enhances
robust and reliable Python code. and more efficient. overall code efficiency and
quality.
Conclusion
Exceptions are inevitable in software development. By mastering the art of
exception handling, you can create more resilient and user-friendly applications.

You might also like