0% found this document useful (0 votes)
7 views

Python Lab Manual Indexed

The KLS GIT-Python Programming Lab Manual outlines a series of experiments and exercises designed to teach students Python programming, including algorithms, flowcharts, and various programming concepts. It includes a lab index with specific tasks such as computing simple interest, finding the largest of two numbers, and creating data structures like lists and dictionaries. The manual also provides grading criteria for assessing students' programming skills and understanding of the material.

Uploaded by

samgameing1257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Lab Manual Indexed

The KLS GIT-Python Programming Lab Manual outlines a series of experiments and exercises designed to teach students Python programming, including algorithms, flowcharts, and various programming concepts. It includes a lab index with specific tasks such as computing simple interest, finding the largest of two numbers, and creating data structures like lists and dictionaries. The manual also provides grading criteria for assessing students' programming skills and understanding of the material.

Uploaded by

samgameing1257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Lab Index
Sub: PYTHON PROGRAMMING Code: 22PLC25B
Expt . No Date Title of the experiment Marks Signature
1 Write an algorithm and Draw Flowchart to
compute Simple interest
2 Write an algorithm and Draw Flowchart to find
the Largest among Two Integer Numbers
3 Program to Compute simple interest and
Compound interest for a given principal amount,
rate of Interest and duration in years.
4 Write a Python program that prompts the user to
enter the quantity of items (an integer) and the
price per item (a floating-point number). Format
the output string to display the total cost with
appropriate formatting.
5 Write a Python program that accepts angle value
in degrees, length X and Y and evaluate the
equation Z=(X*cos(A)) +(Y*sin(A))
6 Write a Python program to find roots of a
quadratic equation.
7 Write a Python program to compute the Factorial
for a given number.
8 Write a python program to find the average of
first n natural numbers.
9 Write a Python program to convert a lowercase string to
uppercase and vice versa and swap the case of the string
which is a mix of lower and upper cases.
10 Write a Python function program to find the sum of
even numbers or odd numbers up to the number
entered by the user
11 Write a python program to find all the positive and
negative numbers in a given list.
12 Write a Python program that creates a list of tuples
called "students" to store the details of multiple students.
Each tuple should contain the student's name, age, and
average score. Prompt the user to enter the details for
three students and store them in the "students" list. Print
the list of tuples
13 Create a dictionary to store the country name and
capitals of the country. Perform the following operations
on dictionary
i) Adding a country to the
dictionary
ii) Deleting a country from the
dictionary
1
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

iii) Find the length of the


Dictionary
AVG Marks.

2
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Lab Exercise -1
Algorithms and Flowcharts
Objective: To understand the concepts of algorithms and drawing flowcharts which
are important to solve any given problem.
Theory
1. Definition of Algorithm: -
• A set of rules/instructions that must be followed when solving a particular problem or
a specific task.
• Algorithms can be simple and complex depending on what you want to achieve.
• Algorithm is generally developed before the actual coding is done.

2. What is the need for algorithms:


a) Algorithms are necessary for solving complex problems efficiently and
effectively.
b) They help to automate processes and make them more reliable, faster, and
easier to perform.
c) Algorithms also enable computers to perform tasks that would be difficult or
impossible for humans to do manually.
d) They are used in various fields such as mathematics, computer science,
engineering, finance, and many others to optimize processes, analyze data,
make predictions, and provide solutions to problems.

3
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

3. Flowchart
The solution of any problem in picture form is called flowchart. It is the one of the most
important techniques to depict an algorithm.
4. Advantage of Flowchart:
• Easier to understand
• Helps to understand logic of problem
• Easy to draw
• Complex problem can be represent using less symbols
• It is the way to documenting any problem
• Helps in debugging process
5. Various symbols – used in flogorithm tool

4
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Application Given: -
1. Compute simple interest

Write Algorithm: -

Observation/ Output
Attach printout of flowchart from Flogarithm tool:

5
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

2. To find the largest and smallest among given two numbers.

Write Algorithm: -

Observation/ Output
Attach printout of flowchart from Flogarithm tool:

6
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Outcomes: -
1. Each student will be able to write the algorithm and draw the flowchart for given
problems which will help them in problem solving. [ PO-1,3,5,10,12]
Category Advanced Proficient Approaching Beginning Marks
( 5 Marks) ( 3 Marks) Proficiency ( 1 Marks)
( 2 Marks)
1. Syntax Program compiles Program compiles Program compiles, Program does not compile
Ability to and contains no and is free from but contains errors or (in a dynamic
understand and evidence of major syntactic that signal language) contains
follow the rules misunderstanding misunderstandings, misunderstanding typographical
of the or misinterpreting but may contain of syntax errors leading to
programming the syntax of the non- standard usage undefined names.
language. language. or superfluous
elements.

2. Logic Program logic is Program logic is Program logic is Program contains some
Ability to correct, with no mostly correct, on the right track conditions that specify the
Specify known boundary but may contain with no infinite opposite of what is
conditions, errors, and no an loops, but shows required (less than vs.
control flow, redundant or occasional boundary no recognition greater than), confuse
and data contradictory error or redundant of boundary Boolean AND/OR
structures that are conditions. or contradictory conditions operators, or lead to
appropriate for condition. (such as < vs. infinite loops.
the problem <=)
domain.

3. Correctness Program produces Program produces Program Program does not produce
Ability to code correct answers correct answers or approaches correct answers or
formulae and or appropriate appropriate results correct answers appropriate results for
algorithms that results for all for most inputs. or appropriate most inputs.
reliably produce inputs tested. results for most
inputs, but can
correct answers or
contain
appropriate results.
miscalculations in
some cases.
4.Completeness Program shows Program shows Program shows Program shows little
Ability to apply evidence of evidence of case some evidence of recognition of how different
rigorous case excellent case analysis that is case analysis, but cases must be handled
analysis to the analysis, and all mostly complete, may be missing differently
problem domain. possible cases are but may have missed significant cases
handled minor or unusual or mistaken in
appropriately. cases. how to handle
some cases.

5.Clarity Program contains Program contains Program contains Program contains no


Ability to format appropriate some documentation some documentation, or grossly
and document code documentation for on major functions, documentation (at misleading indentation.
for human all major variables, or non- least the student’s
consumption. functions, trivial algorithms. name and
variables, or non- Indentation and program’s
trivial algorithms. other formatting is purpose), but has
Formatting, appropriate. occasionally
indentation, and misleading
other white space indentation.
aids readability.

7
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Demonstrate Demonstrate adequate Demonstrate Demonstrate poor ability


6. Viva Voce outstanding ability ability to answer satisfactory ability to answer questions
to answer the questions to answer questions w.r.t. subject matter
questions with w.r.t. subject matter w.r.t. subject matter
clearity, confidence
and appropriateness
w.r.t. subject matter

Total Marks:
Signature of faculty: Checked on:

8
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Lab Exercise -2
Objective: To understand the basic concepts of Operators, Input/output function and
String formatting options in Python.
Theory
Python Operators: Operators are used to perform operations on variables and values.
Arithmetic operators are used with numeric values to perform common mathematical
operations:

Operator Name
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
** Exponentiation
// Floor division

Assignment operators are used to assign values to variables:


Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x-=3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3

Python Relational (Comparison) Operators


Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x>y
< Less than x<y
>= Greater than or equal to x >= y

9
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Python Logical Operators


Operator Description Example
and Returns True if both statements are true x < 5 and x < 10
or Returns True if one of the statements is true x < 5 or x < 4
not Reverse the result, returns False if the result is true not(x < 5 and x < 10)

Function available in math library:


Name Description
sqrt(x) Returns the square root of x
pow(x,y) Returns x raised to y
log10(x) Returns base 10 logarithm of x
pi Returns the mathematical constant pi π
e Returns the mathematical constant
e=2.718281
ceil(x) Returns the smallest integer value
greater than or equal to x.
fabs(x) Returns the absolute value of x
factorial(x) Returns the x factorial
sin(x) Returns the value of sin x in radians
cos(x) Returns the value of cos x in radians
tan(x) Returns the value of tan x in radians
radians(x) Converts the angle x from degrees to
radians
degrees(x) Converts the angle x from radians to
degrees

Python Input and Output statements


• Input statements in python: Most programs accept inputs from the user through
the keyboard. Python provides built-in function for the same.
X=input (“enter a value for X “)
or :
Syntax: for giving the input in integer value
int(x)
For float value
float(x)
Output statements in python
• As the program has to generate output to the standard console, for that a function
print () is used.

1
0
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Definition and Usage of Python format types

The format() method formats the specified value(s) and insert them inside the
string's placeholder.

The placeholder is defined using curly brackets: {}. Read more about the placeholders in
the Placeholder section below.

The format() method returns the formatted string.

Syntax

string.format(value1, value2...)

The Placeholders

The placeholders can be identified using named indexes {price}, numbered indexes {0}, or
even empty placeholders {}.

10
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Applications Given: -
1)Program to Compute simple interest and Compound interest for a given principal amount,
rate of Interest and duration in years.
Note:
Simple interest is calculated with the following formula: S.I. = (P × R × T)/100,
Compound interest is calculated using the formula: C.I.= P × [(1 +R/100) T ] – 1
where P = Principal, R = Rate of Interest in % per annum, and T = Time, usually calculated as
the number of years.

Write Algorithm: -

11
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

2). Write a Python program that prompts the user to enter the quantity of items (an integer) and the
price per item (a floating-point number). Format the output string to display the total cost with
appropriate formatting. Ensure that the price is displayed with two decimal places and the quantity is
displayed as an integer. For example, if the user enters the quantity as 3 and the price as 9.99, the
output should be: "Total cost: 3 items at ₹9.99 each = ₹29.97".

Write Algorithm: -

Observation/ Output: Attach printout of program and output:

12
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

3) Program that accepts angle value in degrees, length X and Y and evaluate the
equation Z=(X*cos(A)) +(Y*sin(A))
Note: use math library
Write Algorithm: -

Observation/ Output
Attach printout of program and output:

13
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Outcomes: -
1. Each student will be able to demonstrate the knowledge of python operators and
format types by writing python programs for the given problems. [ PO-1,2,3,5,9,10,12]
Category Advanced Proficient Approaching Beginning Marks
( 5 Marks) ( 3 Marks) Proficiency ( 1 Marks)
( 2 Marks)
1. Syntax Program compiles Program compiles Program compiles, Program does not compile
Ability to and contains no and is free from but contains errors or (in a dynamic
understand and evidence of major syntactic that signal language) contains
follow the rules misunderstanding misunderstandings, misunderstanding typographical
of the or misinterpreting but may contain of syntax errors leading to
programming the syntax of the non- standard usage undefined names.
language. language. or superfluous
elements.

2. Logic Program logic is Program logic is Program logic is Program contains some
Ability to correct, with no mostly correct, on the right track conditions that specify the
Specify known boundary but may contain with no infinite opposite of what is
conditions, errors, and no an loops, but shows required (less than vs.
control flow, redundant or occasional boundary no recognition greater than), confuse
and data contradictory error or redundant of boundary Boolean AND/OR
structures that are conditions. or contradictory conditions operators, or lead to
appropriate for condition. (such as < vs. infinite loops.
the problem <=)
domain.

3. Correctness Program produces Program produces Program Program does not produce
Ability to code correct answers correct answers or approaches correct answers or
formulae and or appropriate appropriate results correct answers appropriate results for
algorithms that results for all for most inputs. or appropriate most inputs.
reliably produce inputs tested. results for most
inputs, but can
correct answers or
contain
appropriate results.
miscalculations in
some cases.
4.Completeness Program shows Program shows Program shows Program shows little
Ability to apply evidence of evidence of case some evidence of recognition of how different
rigorous case excellent case analysis that is case analysis, but cases must be handled
analysis to the analysis, and all mostly complete, may be missing differently
problem domain. possible cases are but may have missed significant cases
handled minor or unusual or mistaken in
appropriately. cases. how to handle
some cases.

5.Clarity Program contains Program contains Program contains Program contains no


Ability to format appropriate some documentation some documentation, or grossly
and document code documentation for on major functions, documentation (at misleading indentation.
for human all major variables, or non- least the student’s
consumption. functions, trivial algorithms. name and
variables, or non- Indentation and program’s
trivial algorithms. other formatting is purpose), but has
Formatting, appropriate. occasionally
indentation, and misleading
other white space indentation.
aids readability.

14
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Demonstrate Demonstrate adequate Demonstrate Demonstrate poor ability


6. Viva Voce outstanding ability ability to answer satisfactory ability to answer questions
to answer the questions to answer questions w.r.t. subject matter
questions with w.r.t. subject matter w.r.t. subject matter
clearity, confidence
and appropriateness
w.r.t. subject matter

Total Marks:
Signature of faculty: Checked on:

15
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Lab Exercises - on Unit 3 (Control structures)


Objective: To understand the basic concepts of various Types of Control Structures in
Python

Theory
Introduction:
Programs are written for the solution to the real-world problems. A language should have the
ability to control the flow of execution so that at different intervals different statements can
be executed. Structured programming is a paradigm aims at controlling the flow of execution
of statements in a program by using control structures.
A language which supports the control structures is called as structured programming
language

Types of Control Structures


A Structured programming is an important feature of a programming language which
comprises following logical structure:

1. Sequence
2. Selection
3. Iteration Or Looping
4. Branching Or Jumping Statements

1. Sequence
Sequence is the default control structure; instructions are executed one after
another. Statement 1
Statement 2
Statement 3
……..
……..
……..

16
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Flow Chart for Sequence

Example on Sequence - Program


Sequence is the default control structure; instructions are executed one after
another. # This program adds two numbers
def sum_of_two_no():
num1 = 1.5
num2 = 6.3
sum = float(num1) + float(num2)
print('The sum is =‘, sum)
sum_of_two_no():

2. Selection
A selection statement causes the program control to be transferred to a specific flow based
upon whether a certain condition is true or not.

Flow Chart for Selection

Example on Selection - Program


Sequence is the default control structure; instructions are executed one after
another. # This program adds two numbers
def sum_of_two_no():
num1 = 1.5
num2 = 6.3
sum = float(num1) + float(num2)

17
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

print('The sum is =‘, sum)


sum_of_two_no():

Conditional Construct – If Else Statement


Conditional constructs (also known as if statements) provide a way to execute a chosen
block of code based on the run-time evaluation of one or more Boolean expressions. In
Python, the most general form of a conditional is written as follows:

 Each condition is a Boolean expression, and each body contains one or more
commands that are to be executed conditionally.
 If the first condition succeeds, the first body will be executed; no other
conditions or bodies are evaluated in that case.
 If the first condition fails, then the process continues in similar manner with
the evaluation of the second condition. The execution of this overall construct
will cause precisely one of the bodies to be executed.
 There may be any number of elif clauses (including zero), and
 The final else clause is optional.

Flow Chart for Conditional Construct – If Else Statement

18
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Example on Conditional Construct – If Statement Program

Example on Conditional Construct – If Else Statement Program

19
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Example on Conditional Construct – If Elif Statement Program

Sample problem statements for self-study purpose


Below Average Programs
1. Write a PYTHON program that reads a value of n and check
the number is zero or non-zero value.
2. Write a PYTHON program to find a largest of two numbers.
3. Write a PYTHON program that reads the number and check the no
is positive or negative.
4. Write a PYTHON program to check entered character is vowel
or consonant.
Average Programs
5. Write a PYTHON program to evaluate the student
performance If % is >=90 then Excellent performance
If % is >=80 then Very Good
performance If % is >=70 then Good
performance
If % is >=60 then average performance
else Poor performance.
6. Write a PYTHON program to find largest of three numbers.
7. Write a PYTHON program to find smallest of three
numbers Above Average Programs
8.Write a PYTHON program to check weather number is even or
odd. 9.Write a PYTHON program to check a year for leap year.
10. A company insures its drivers in the following cases:
- If the driver is married.
- If the driver is unmarried, male and above 30 years of age.
- If the driver is unmarried, female and above 25 years of
age. In all the other cases, the driver is not insured.
If the marital status, sex and age of the driver are the inputs,
20
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Write a PYTHON program to determine whether the driver is insured


or not

3. Iteration or Looping

What is loop or iteration?


Loops can execute a block of code number of times until a certain
condition is met.
OR
The iteration statement allows instructions to be executed until a
certain condition is to be fulfilled.
The iteration statements are also called as loops or Looping statements.

Python provides two kinds of loops & they are,

while loop

A while loop allows general repetition based upon the repeated testing of a Boolean
condition

The syntax for a while loop in Python is as follows:

while condition:
body
Where, loop body contain the single statement or set of statements (compound
statement) or an empty statement.

The loop iterates while the expression evaluates to true, when expression becomes
false the loop terminates.

21
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

while loop – Programming example

22
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Sample problem statements for self-study purpose


Below Average Programs
1. Write a PYTHON program to print the natural numbers up to n
2. Write a PYTHON program to print even numbers up to n
3. Write a PYTHON program to print odd numbers up to n
4. Write a PYTHON program to print sum of natural numbers up to
n Average Programs
5. Write a PYTHON program to print sum of odd numbers up to n
6. Write a PYTHON program to print sum of even numbers up to n
7. Write a PYTHON program to print natural numbers up to n in reverse order.
8. Write a PYTHON program to print Fibonacci series up to n
9. Write a PYTHON program find a factorial of given
number Above Average Programs
10. Write a PYTHON program to check the entered number is prime or not
11. Write a PYTHON program to find the sum of digits of given number

23
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

12. Write a PYTHON program to check the entered number is palindrome


or not
13. Write a PYTHON program to reverse the given number.

for LOOP
Python’s for-loop syntax is a more convenient alternative to a while loop when
iterating through a series of elements. The for-loop syntax can be used on any type of
iterable structure, such as a list, tuple str, set, dict, or file

Syntax or general format of for loop is,

for element in iterable:


body

for LOOP - range KEYWORD

24
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

25
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

for LOOP – len() FUNCTION

else statement in loop


else can be used in for and while loops the else body will be executed as and when the
loop’s conditional expression evaluates to false

Sample problem statements for self-study purpose


Below Average Programs
1. Write a PYTHON program to print the natural numbers up to n
2. Write a PYTHON program to print even numbers up to n
3. Write a PYTHON program to print odd numbers up to n
4. Write a PYTHON program that prints 1 2 4 8 16 32 … n2
5. Write a PYTHON program to sum the given
sequence 1 + 1/ 1! + 1/ 2! + 1/3! + …. + 1/n!
Average Programs
6. Write a PYTHON program to compute the cosine
series cos(x) = 1 – x2 / 2! + x4 / 4! – x6 / 6! + … xn
/ n!
26
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

7. Write a short PYTHON program to check weather the square root


of number is prime or not.
8. Write a PYTHON program to produce following
design A B C
ABC
AB
C
Above Average Programs
9. Write a PYTHON program to produce following
design A
A B
AB
C
ABCD
ABCD
E
If user enters n value as 5
10. Write a PYTHON program to produce following
design A B C D E
ABCD
ABC
AB
A
(If user enters n value as 5)
11. Write a PYTHON program to produce following
design 1
12
123
1234
12345
If user enters n value as 5
12. Write a PYTHON program to produce following
design 1
22
333
4444
55555
If user enters n value as 5

4. Branching or Jumping Statements


Python has an unconditional branching statements and they are,

27
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

1. break STATEMENT

28
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Break can be used to unconditionally jump out of the loop. It terminates the execution
of the loop. Break can be used in while loop and for loop. Break is mostly required,
when because of some external condition, we need to exit from a loop.

2. continue STATEMENT
The continue statement in Python returns the control to the beginning of the while
loop. The continue statement rejects all the remaining statements in the current
iteration of the loop and moves the control back to the top of the loop. The continue
statement can be used in both while and for loops.

29
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

pass STATEMENT
The pass statement in Python is used when a statement is required syntactically but
you do not want any command or code to execute.
The pass statement is a null operation; nothing happens when it executes.
The pass is also useful in places where your code will eventually go, but has
not been written yet (e.g., in stubs for example):

21
0
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Difference Between break and continue

30
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

3A) Write a Python program to find roots of a quadratic equation.


Note:
Quadratic equation is an equation of the second order polynomial specified with three
coefficients a, b and c. If a=0 it is not a quadratic equation. The quadratic equation takes the
form as specified below

𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
The solution to the quadratic equation is given by two roots x1 and x2 and is computed with
the following formula.

=( )
−𝑏±√𝑏2−4𝑎𝑐
x
2𝑎
(1,2)

The content inside the square root is known as the discriminant and specified by Δ
Δ=b2-4ac
If Δ>0 the roots are real and distinct and is given as below:
(−𝑏+√𝛥)
2𝑎
x1 =

(−𝑏−√𝛥)
2𝑎
x2 =

If Δ<0 the roots are imaginary and are represented as complex roots as given below:
(−𝑏+𝑖√𝛥)
2𝑎
x1 =

(−𝑏−𝑖√−𝛥)
2𝑎
x2 =

If Δ==0 then the roots are equal and are a given below:
−𝑏
x1= x2=
2𝑎

31
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

32
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

3B) Write a Python program to compute the Factorial for a given number.
Note:

33
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Write Algorithm: -

Observation/ Output: Attach printout of program and output:

34
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

3C) Write a python program to find the average of first n natural numbers.
Note:
Natural numbers are a part of the number system, including all the positive numbers from 1 to
infinity. Natural numbers are also known as counting numbers because they do not include
zero or negative numbers. They are a part of real numbers including only the positive
integers, but not zero, fractions, decimals, and negative numbers.

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

35
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

4a) Write a Python program to convert a lowercase string to uppercase and vice versa and swap
the case of the string which is a mix of lower and upper cases

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

36
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

4b) Write a Python function program to find the sum of even numbers or odd numbers up to
the number entered by the user.

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

37
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Outcomes: -
Each student will be able to demonstrate the knowledge of conditional statements and
looping by writing python programs for the given problems. [ PO-1,2,3,5,9,10,12]
Category Advanced Proficient Approaching Beginning Marks
( 5 Marks) ( 3 Marks) Proficiency ( 1 Marks)
( 2 Marks)
1. Syntax Program compiles Program compiles Program compiles, Program does not compile
Ability to and contains no and is free from but contains errors or (in a dynamic
understand and evidence of major syntactic that signal language) contains
follow the rules misunderstanding misunderstandings, misunderstanding typographical
of the or misinterpreting but may contain of syntax errors leading to
programming the syntax of the non- standard usage undefined names.
language. language. or superfluous
elements.

2. Logic Program logic is Program logic is Program logic is Program contains some
Ability to correct, with no mostly correct, on the right track conditions that specify the
Specify known boundary but may contain with no infinite opposite of what is
conditions, errors, and no an loops, but shows required (less than vs.
control flow, redundant or occasional boundary no recognition greater than), confuse
and data contradictory error or redundant of boundary Boolean AND/OR
structures that are conditions. or contradictory conditions operators, or lead to
appropriate for condition. (such as < vs. infinite loops.
the problem <=)
domain.

3. Correctness Program produces Program produces Program Program does not produce
Ability to code correct answers correct answers or approaches correct answers or
formulae and or appropriate appropriate results correct answers appropriate results for
algorithms that results for all for most inputs. or appropriate most inputs.
reliably produce inputs tested. results for most
inputs, but can
correct answers or
contain
appropriate results.
miscalculations in
some cases.
4.Completeness Program shows Program shows Program shows Program shows little
Ability to apply evidence of evidence of case some evidence of recognition of how different
rigorous case excellent case analysis that is case analysis, but cases must be handled
analysis to the analysis, and all mostly complete, may be missing differently
problem domain. possible cases are but may have missed significant cases
handled minor or unusual or mistaken in
appropriately. cases. how to handle
some cases.

5.Clarity Program contains Program contains Program contains Program contains no


Ability to format appropriate some documentation some documentation, or grossly
and document code documentation for on major functions, documentation (at misleading indentation.
for human all major variables, or non- least the student’s
consumption. functions, trivial algorithms. name and
variables, or non- Indentation and program’s
trivial algorithms. other formatting is purpose), but has
Formatting, appropriate. occasionally
indentation, and misleading
other white space indentation.
aids readability.

38
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Demonstrate Demonstrate adequate Demonstrate Demonstrate poor ability


6. Viva Voce outstanding ability ability to answer satisfactory ability to answer questions
to answer the questions to answer questions w.r.t. subject matter
questions with w.r.t. subject matter w.r.t. subject matter
clearity, confidence
and appropriateness
w.r.t. subject matter

Total Marks:
Signature of faculty: Checked on:

39
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

5a) Write a python program to find all the positive and negative numbers in a given list.

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

31
0
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

5b) Write a Python program that creates a list of tuples called "students" to store the details of multiple students. Each
tuple should contain the student's name, age, and average score. Prompt the user to enter the details for three students
and store them in the "students" list. Print the list of tuples

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

31
1
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

5c) Create a dictionary to store the country name and capitals of the country. Perform the following operations on
dictionary
i) Adding a country to the dictionary
ii) Deleting a country from the dictionary
iii) Find the length of the Dictionary

Write Algorithm: -

Observation/ Output
Attach printout of program and output:

31
2
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Outcomes: -
Each student will be able to demonstrate the knowledge of conditional statements and
looping by writing python programs for the given problems. [ PO-1,2,3,5,9,10,12]
Category Advance Proficient Approaching Beginning Marks
d(5 ( 3 Marks) Proficiency ( 1 Marks)
Marks) ( 2 Marks)
1. Syntax Program Program compiles Program compiles, Program does not compile
Ability to compiles and and is free from but contains errors or (in a dynamic
understand and contains no major syntactic that signal language) contains
follow the rules evidence of misunderstandings, misunderstanding typographical
of the misunderstandin but may contain of syntax errors leading to
programming g or non- standard usage undefined names.
language. misinterpreting or superfluous
the syntax of the elements.
language.
2. Logic Program logic is Program logic is Program logic is Program contains some
Ability to correct, with no mostly correct, on the right track conditions that specify the
Specify known but may contain with no infinite opposite of what is
conditions, boundary an loops, but shows required (less than vs.
control flow, errors, and no occasional boundary no recognition greater than), confuse
and data redundant or error or redundant of boundary Boolean AND/OR
structures that are contradictory or contradictory conditions operators, or lead to
appropriate for conditions. condition. (such as < vs. infinite loops.
the problem <=)
domain.
3. Correctness Program Program produces Program Program does not produce
Ability to code produces correct correct answers or approaches correct answers or
formulae and answers or appropriate results correct answers appropriate results for
algorithms that appropriate for most inputs. or appropriate most inputs.
reliably produce results for all results for most
inputs, but can
correct answers or inputs tested.
contain
appropriate results.
miscalculations in
some cases.
4.Completeness Program Program shows Program shows Program shows little
Ability to apply shows evidence of case some evidence of recognition of how different
rigorous case evidence of analysis that is case analysis, but cases must be handled
analysis to the excellent case mostly complete, may be missing differently
problem domain. analysis, and all but may have missed significant cases
possible cases minor or unusual or mistaken in
are handled cases. how to handle
appropriately. some cases.
5.Clarity Program Program contains Program contains Program contains no
Ability to format and contains some documentation some documentation, or grossly
document code for appropriate on major functions, documentation (at misleading indentation.
human documentation variables, or non- least the student’s
consumption. for all major trivial algorithms. name and
functions, Indentation and program’s
variables, or other formatting is purpose), but has
non- trivial appropriate. occasionally
algorithms. misleading
Formatting, indentation.
indentation, and
other white
space
aids readability.
31
3
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

Demonstrate Demonstrate adequate Demonstrate Demonstrate poor ability


6. Viva Voce outstanding ability ability to answer satisfactory ability to answer questions
to answer the questions to answer questions w.r.t. subject matter
questions with w.r.t. subject matter w.r.t. subject matter
clearity, confidence
and appropriateness
w.r.t. subject matter

Total Marks:
Signature of faculty: Checked on:

Index
Experiment No. Date Title of the Experiment Marks Signature
1 Write an algorithm
and Draw Flowchart
to compute Simple
Interest
2 Write an algorithm
and Draw Flowchart
to find the Largest
among Two Integer
Numbers
3 Program to Compute
simple interest and
Compound interest for
a given principal
amount, rate of
Interest and duration
in years.
4 Write a Python
program that prompts
the user to enter the
quantity of items and
the price per item,
formatted output.
5 Write a Python
program to evaluate
Z=(X*cos(A)) +
(Y*sin(A)) for given
values.
6 Write a Python
program to find roots
of a quadratic
equation.
7 Write a Python
program to compute
the Factorial for a
given number.
8 Write a python
program to find the
average of first n
natural numbers.
9 Write a Python
31
4
KLS, GIT-PYTHON PROGRAMMING LAB MANUAL (22PLC25B)

program to convert a
lowercase string to
uppercase and vice
versa.
10 Write a Python
function program to
find the sum of even
or odd numbers up to
user input.

31
5

You might also like