0% found this document useful (0 votes)
11 views15 pages

Excercise Note Cum Lab Manual_Problem Solving Using Python

The document is a lab manual for a Python programming course at Vellore Institute of Technology, outlining the vision, mission, course objectives, outcomes, and grading rubric. It includes exercises on Python basics, data types, control flow, and specific programming tasks related to agricultural subsidies and user validation. The manual aims to equip students with algorithmic skills and data handling techniques through practical programming exercises.

Uploaded by

Frag Slayer
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)
11 views15 pages

Excercise Note Cum Lab Manual_Problem Solving Using Python

The document is a lab manual for a Python programming course at Vellore Institute of Technology, outlining the vision, mission, course objectives, outcomes, and grading rubric. It includes exercises on Python basics, data types, control flow, and specific programming tasks related to agricultural subsidies and user validation. The manual aims to equip students with algorithmic skills and data handling techniques through practical programming exercises.

Uploaded by

Frag Slayer
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/ 15

BACSE101 Problem Solving Using Python Lab

Lab Manual

Exercise Note Book Cum Lab Manual

Vellore Institute of Technology,


Chennai

1 Prepared by Dr.M.A Inayathullaah


SCHOOL OF ELECTRICAL ENGINEERING

Vision of the School

To offer an education in electrical engineering that provides strong fundamental


knowledge, skills for employability, cross-disciplinary research and creates
leaders who provide technological solutions to societal and industry problems.

Mission of the School

M1: Provide personalized experiential learning in industry sponsored


laboratories to prepare students in electrical engineering with strong critical
thinking and employability skills.
M2: Foster design thinking, creativity and cross-disciplinary research with highly
qualified faculty to create innovators and entrepreneurs in the broad area of
electrical engineering.
M3:Collaborate with national and international partners to provide innovative
solutions to societal and industry challenges.

2 Prepared by Dr.M.A Inayathullaah


Course Objectives

1. To provide the basics and fundamentals of the python programming


language and introduce algorithmic skills through programming
constructs
2. To impart python collections for efficient data handling and processing
and inculcate modular and recursive programming approaches for
developing software applications
3. To teach python libraries for data analysis and manipulations
Course Outcomes

At the end of the course, students should be able to


1. Identify appropriate algorithmic approaches, data representation, control
constructs in developing software solutions for solving real-world
problems.
2. Inculcate data handling techniques using python collections and modular
programming strategies for developing multi-disciplinary software
applications
3. Idealize the importance of python libraries for handling, manipulating and
analyzing multi-faceted real world problem domains.

3 Prepared by Dr.M.A Inayathullaah


LAB EXCERSICE GRADING RUBRIC

Criteria & Point Below


Acceptable Considerable Unacceptable Total
Assessment Assigned Expectations
( 2) (1.5) (0) Marks
Content (1)

Pre Lab
Assessment Most of Some of Few of
Capability of
(Immediately algorithms or algorithms or algorithms or No algorithms
writing
after procedures procedures are procedures or procedures 2
Algorithm/Drawing
entering the are written written are written are written.
Flow Chart
lab) clearly. undoubtedly. clearly.

All programs Programs are


are written Some programs Major errors not
Capability of
In Lab precisely based are written in program written/wrong 1
writing Program
Assessment on the accurately. writing. program
(Before question. written.
leaving the
Represent all
lab)
data
Major part Wrong
appropriately. Partly outputs
Result or Output of output not output/no 2
Finding of are found.
found. output found.
results are
clear.
Proper Time i.e. Submission of
in within three Lab , Fair Copy
Very
Attention to Lab day of lab., in proper time Late
Post Lab poor 2
Fair Copy with but not with Submission.
( Within presentation.
proper proper
three day of documentation. documentation.
lab)
Partial
Completing
Completing Completed
Completion of within three Late
within three and not 3
Exercise days and Submission.
days and getting wetted
getting wetted
wetted

Total Marks 10

4 Prepared by Dr.M.A Inayathullaah


List of Experiments

Sl.No. Name of the Experiment Remarks Mark


1 Experiment on data types and sequential
statements: Subsidy Computation
2
3
4
5
6
7
8
9
10

5 Prepared by Dr.M.A Inayathullaah


Python Basics

1. Indentation in Python
Python Indentation refers to the use of whitespace (spaces or tabs) at the
beginning of code line.

2. Python Variables
A variable is essentially a name that is assigned to a value. We don't need to
declare a variable's type explicitly in Python. Based on the value assigned,
Python will dynamically determine the type.

Rules for Naming Variables

• Variable names can only contain letters, digits and underscores (_).
• A variable name cannot start with a digit.
• Variable names are case-sensitive (myVar and myvar are different).
• Avoid using Python keywords (e.g., if, else, for) as variable names.
3. Variable assignments

6 Prepared by Dr.M.A Inayathullaah


4. Python Identifiers
The Python, identifiers are unique names that are assigned to variables,
functions, classes, and other entities. They should start with a letter (a-z, A-Z)
or an underscore "_" and can be followed by letters, numbers, or underscores.

5. Python keywords
Keywords in Python are reserved words that have special meanings and serve
specific purposes in the language syntax. They cannot be used as identifiers,
names for variables, functions, classes, etc.

6. Comments in Python
Single line comments are preceded by the "#" symbol. Python uses multi-line
comments. As one after the other, or sometimes triple quotes (either ''' or """),

7 Prepared by Dr.M.A Inayathullaah


7. Backslashes (\)
Used to split a sentence to multiple lines

8. Continuation of Statements in Python


This continuation of statements over multiple lines is supported in Python in
various ways: Implicit Continuation ; Python implicitly supports line
continuation within parentheses (), square brackets [], and curly braces
{}. Explicit Continuation; You can use backslash '\' to indicate that a statement
should continue on the next line.

9. Taking Input from User in Python


The input() function in Python is used to take user input from the console. The
program execution halts until the
user provides input and presses
"Enter".

8 Prepared by Dr.M.A Inayathullaah


10.Python operators
Operators in Python are special symbols used to perform operations on variables
and values.

11.Python Control flow statements


Conditional statements (if, elif, else) execute code blocks based on conditions.

9 Prepared by Dr.M.A Inayathullaah


12.Python looping statements
Loop statements (for, while) repeat code blocks

a. for loops iterate over a sequence (lists, tuples, etc.).

10 Prepared by Dr.M.A Inayathullaah


b. while loops repeat as long as a condition is true.

11 Prepared by Dr.M.A Inayathullaah


Experiment No. 1

DATE:

Learning on: Data Types: Numeric, Boolean and Strings - Regular Expression - Operators - Expressions
- Built in Functions
Problem statement:

Agricultural subsidies are offered by the Indian government to farmers for improving crop yields and
benefiting them. To facilitate the farmers in finding the subsidy amount, develop a Python code to
calculate the subsidy based on the crop the farmer grows. The farmers can grow one of these
three types of crops: Rice, Wheat, or Maize. Each crop has a different formula for calculating the
subsidy:
Formula:
Rice: Subsidy= (Yield × Market Rate) + 100
Wheat: Subsidy= (Yield × Market Rate) + 200
Maize: Subsidy= (Yield × Market Rate) + 300
Use menu driven approach to implement the same.

Software Tool: Google Colab

Flow chart:
Start Program

Display Menu:
1. Rice 2. Wheat 3. Maize 4. Exit

Get User Choice 1 or 2 or 3 or 4

Input Yield, Market, Rate

Calculate Subsidy:
For Rice: (Yield × Market Rate) + 100
Invalid Input
For Wheat: (Yield × Market Rate) + 200
For Maize: (Yield × Market Rate) + 300

If the
Display subsidy and Return to Menu choice is 4

12 Prepared by Dr.M.A Inayathullaah


Snapshot of Program:

Snapshot of Input and output:

13 Prepared by Dr.M.A Inayathullaah


Learning Outcome:

Prelab mark Inlab Mark Post Lab mark

Post lab Activities

• Exercise Problem 1:

Climate Change Data Analyzer


Scientists track daily temperatures as a string of values separated by spaces (e.g., "30.5 32.1 29.8").
Write a Python program that extracts the temperatures, converts them into float values, and finds
the highest, lowest, and average temperature.
Rules & Constraints:
i. Input is a string of space-separated float values (e.g., "30.5 31.2").
ii. All values must be valid floating-point numbers.
iii. The list must have at least two values.
iv. Temperatures must be within a realistic range: -100.0°C to 60.0°C.
v. The program should round the average to two decimal places.
vi. If the input is invalid (non-numeric, empty, out-of-range), return an error message.

• Exercise Problem 2:

Gaming Leaderboard Username Validator


In an online game, players choose usernames for the leaderboard. To make sure all usernames are
clean and fair, they must follow these rules:
i. The username must start with a letter (A–Z or a–z).
ii. It can contain letters, numbers, and underscores (_) only.
iii. It cannot start with a number.
iv. No other symbols or spaces are allowed.
v. The length must be between 5 and 15 characters.

14 Prepared by Dr.M.A Inayathullaah


Write a Python program using regular expressions to check if a username is valid or invalid. If
invalid, display a message “Invalid Name”

• Exercise Problem 3:

Gaming Leaderboard Username Validator


In an online game, players choose usernames for the leaderboard. To make sure all usernames are
clean and fair, they must follow these rules:
i. The username must start with a letter (A–Z or a–z).
ii. It can contain letters, numbers, and underscores (_) only.
iii. It cannot start with a number.
iv. No other symbols or spaces are allowed.
v. The length must be between 5 and 15 characters.
Write a Python program using regular expressions to check if a username is valid or invalid. If
invalid, display a message “Invalid Name”

• Exercise Problem 4:

Number Game

In Numeria, Alchemists must build an arithmetic expression using given numbers and operations to
match a target. Use each number once, with +, -, *, or /. If no exact match, return the expression
closest to the target. If multiple expressions give the same best result, return "No single solution"
Rules:
i. Use all numbers once.
ii. Only +, -, *, / allowed.
iii. Division must result in integers only.
iv. Left-to-right evaluation only (no brackets)
v. All numbers must be positive integers.
vi. Return one valid expression, or "No single solution" if ties exist.

15 Prepared by Dr.M.A Inayathullaah

You might also like