Python Practicals Amrita

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Lab Manual

Introduction to
Problem Solving
CSE1021

Submitted by

Name: satendra singh


Reg. No: 23BEC10073

Bachelor of Technology
in
CSE- AI and ML

Submitted to
School of Computing Science and Engineering
VIT Bhopal University

Date of Submission:
04.12.23
Table of Contents

S.No. Experiment Page. No.


Title
Problem Solving: Drawing Flowchart Using
1 Tool 1

2 Basic programs in Python: Input and output 4


Operations
3 Programs using basic commands and simple 8
conditional statements
4 Programs using conditional statements and 12
looping
5 Programs using Factoring Methods 15

6 Programs using Array Technique 18

7 Programs using Lists 21


1. Problem Solving: Drawing Flowchart Using Raptor Tool

a. How can you Solve the Problem Computationally?

Ans: The approach to solving a problem computationally depends on the nature


of the problem itself. Here are some general steps and methods that can be applied:

i. Define the Problem:


Clearly articulate the problem you are trying to solve. Understand the inputs, outputs,
constraints, and requirements.

ii. Algorithm Design:


Develop an algorithm to solve the problem. Break down the problem into smaller,
more manageable sub-problems. Consider the efficiency of the algorithm in terms of
time and space complexity.

iii. Choose a Programming Language:


Select a programming language that is suitable for the problem at hand. Different
languages have different strengths, and choosing the right one can make a significant
difference in development time and performance.

iv. Implement the Algorithm:


Write the code to implement the algorithm. Follow best practices for coding, such as
modularization, commenting, and adhering to coding standards.

v. Testing:
Test the program with various inputs to ensure that it produces the correct outputs.
Consider edge cases and scenarios that might lead to unexpected behavior.

vi. Optimization:
Analyze the performance of your code and identify areas for improvement. This
might involve optimizing algorithms, improving data structures, or making other
changes to enhance efficiency.

vii. Debugging:
If there are errors or unexpected behavior, use debugging tools and techniques to
identify and fix the issues in your code.
viii. Documentation:
Document your code thoroughly. This includes writing comments, creating user
documentation, and providing explanations for complex sections of the code. Clear
documentation makes it easier for others (or yourself in the future) to understand and
maintain the code.
ix. Deployment:
Deploy the solution in the desired environment. This might involve integrating your
code with other systems, setting up a user interface, or making it accessible to others.

x. Maintenance:
Periodically revisit and update the code as needed. This includes fixing bugs, adding
new features, or adapting the code to changes in the environment or requirements.

b. Determine if a number is even or odd.

Ans:

c. Find the greatest number among the three given numbers.

Ans:
2. Basic programs in Python: Input and output Operations

a. Explain flow of python programs.

Ans: The flow of a Python program typically follows a sequential order, with
the interpreter executing each statement one after another. Here's a brief
overview of the typical flow in a Python program:

i. Sequential Execution:
Python programs are executed sequentially, starting from the top of the file and
moving downward. Each statement is executed one after the other in the order
in which they appear.

ii. Conditional Statements (if, elif, else):


Conditional statements allow you to execute different blocks of code based on
whether a certain condition is true or false.

iii. Loops (for, while):


Loops allow you to repeat a block of code multiple times. The for loop is
typically used for iterating over a sequence (e.g., a list), while the while loop
continues until a certain condition is false.

iv. Functions:
Functions are blocks of reusable code that can be called with a specific set of
inputs (arguments). They help in modularizing code.

v. Exception Handling (try, except):


Exception handling is used to deal with errors and unexpected situations. The
try block contains the code that might raise an exception, and the except block
contains the code to handle the exception.

vi. Module Imports:


Python allows you to use modules and packages to organize code. You can
import modules at the beginning of your program to use their functionality.

b. To Convert Celsius to Fahrenheit.

Ans:

#Code
#Output

c. To Find Factorial of a Number.

Ans:

#Code
#Output

d. To find the multiplication of a given number.

Ans:

#Code
#Output

3. Programs using basic commands and simple conditional statements.

a. Check if a Number is Positive, Negative, or Zero.

Ans:

#Code
#Output

b. Check if a Year is a Leap Year.

Ans:

#Code
#Output

c. Count Vowels and Consonants.

Ans:

#Code
#Output

d. Print ASCII Value of a Character.

Ans:

#Code
#Output

4. Programs using conditional statements and looping.

a. Display Fibonacci Series of a given number.

Ans:

#Code
#Output

b. To display Pattern Printing - Right Angle Triangle.

Ans:

#Code
#Output

c. Program for Prime Number Checker.

Ans:

#Code
#Output

5. Programs using Factoring Methods.

a. LCM (Least Common Multiple) of Two Numbers.

Ans:

#Code
#Output

b. Prime Factorization of a Number.

Ans:

#Code
#Output

c. Calculate the Sum of Divisors of a Number.

Ans:

#Code
#Output

6. Programs using Array Technique.


a. Finding Maximum and Minimum Element in an Array.

Ans:

#Code
#Output

b. Removing Duplicates from an Array.

Ans:

#Code
#Output

c. Checking for Palindrome Array.

Ans:

#Code
#Output

7. Programs using Lists.


a. To find Common Elements in Two Lists.

Ans:

#Code
#Output

b. Count Occurrences of an Element in a List.

Ans:

#Code
#Output

c. Reverse a List.

Ans:

#Code
#Output

d. Remove Negative Numbers from a List.

Ans:

#Code
#Output

You might also like