0% found this document useful (0 votes)
12 views30 pages

Python Programming Practical File

The document is a practical file for Python programming (CSP3015) submitted by Karanjit Singh, detailing various Python programs categorized by operators, conditional statements, iterative statements, strings, and lists. Each section includes problem statements and examples for programs like a pocket money calculator, leap year verifier, and a water intake tracker. The file serves as a comprehensive guide for implementing practical Python applications for different scenarios.

Uploaded by

Manikaran
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)
12 views30 pages

Python Programming Practical File

The document is a practical file for Python programming (CSP3015) submitted by Karanjit Singh, detailing various Python programs categorized by operators, conditional statements, iterative statements, strings, and lists. Each section includes problem statements and examples for programs like a pocket money calculator, leap year verifier, and a water intake tracker. The file serves as a comprehensive guide for implementing practical Python applications for different scenarios.

Uploaded by

Manikaran
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

Practical File

of
Python Programming
(CSP3015)

Submitted to: Submitted by:


Dr. Jaswinder Singh Karanjit Singh
Mr. Sandeep Waraich 28202301520
Dr. Deepali Bassi MCA(FYIP) 5th Sem - A
INDEX
Sr. No. Problem Statement Page No.
1 Python Programs using Operators 1-6
i. Pocket Money Calculator
ii. Candy Distribution
iii. Fuel Efficiency Estimator
iv. Trip Budget Calculation
v. Walk and lose weight
vi. Track university reaching time
2 Python Programs using Conditional statements 7-10
i. Verify if the year is a Leap year
ii. Alarm for the weekend
iii. Group Assignment
iv. Securing your online account
3 Python Programs using Iterative statements 11-20
i. Reversing ticket number
ii. Decode the hidden message in the number
iii. Squid Game found
iv. Water intake Tracker
v. Weekly Grocery Budget
vi. Magical Potion Brewer
vii. Pirate Treasure Hunt
viii. Prime number grid puzzle
ix. Talent show pyramid
x. Auto-driving cars and traffic signals
4 Python Programs using Strings 21-25
i. Count the frequency of a character in a string
ii. Count the frequency of a word in a string
iii. Longest substring without repeating a character
iv. Input a string having digits and print the sum of digits
present in the string
v. Input a string and a character. Delete the occurrence of the
character in the given string.
5 Python programs using Lists
i. Weather data analysis
ii. Stock market investment
iii. Freelance earning calculation
iv. Twitter hashtag trending
v. Monster hunt
vi. Freelance rating

Signatures: ____________________________
1. Python Programs using Operators
i. Pocket Money Calculator
You receive a fixed amount of pocket money each week and want to know how much
you’ll have after saving for a certain number of weeks. Create a program in Python that
takes the amount of pocket money per week and the number of weeks as input and
calculates the total amount saved.

INPUT:

OUTPUT:

ii. Candy Distribution

1
You have a certain number of candies and want to share them equally among your
friends. Write a program in Python that takes the total number of candies and the number
of friends as input and calculates how many candies each friend will get and how many
will be left over.

INPUT:

OUTPUT:

iii. Fuel Efficiency Estimator


You want to calculate how far you can travel with a certain amount of fuel in your car.
Develop a Python snippet that takes the distance your car can travel per liter of fuel (fuel
efficiency) and the amount of fuel you have as input, and calculates the total distance
you can travel.

2
INPUT:

OUTPUT:

iv. Trip Budget Calculation


You’re planning a trip and want to calculate your total budget, including
accommodation, food, and entertainment. Develop a Python code that takes the daily
costs for accommodation, food, and entertainment, and the number of days you’ll be
staying, and calculates the total trip cost.

INPUT:
3
OUTPUT:

v. Walk and lose weight


You’ve set a goal to lose a certain amount of weight by walking over a specific period.
You know that on average, walking 1 kilometer burns approximately 60 calories, and to
lose 1 kilogram of body weight, you need to burn about 7700 calories. Given your target
weight loss and the number of days you have to achieve it, calculate how many
kilometers you need to walk each day to reach your goal. Write a Python program that
takes your target weight loss (in kilograms) and the number of days you plan to achieve
this goal. The program should calculate and output the number of kilometers you need to
walk each day to reach your target.

INPUT:
4
OUTPUT:

vi. Track university reaching time


You’re getting ready for university and need to determine if you’ll reach your class on
time. To figure this out, you need to calculate the time it will take to travel to your
college based on the distance, your average speed, and the time remaining until your
class starts.
You are tasked to create a program in Python that will require you to input the distance
to your college in kilometers, your average speed in kilometers per hour, the current time
in 24-hour format (hours and minutes), and the time remaining until your class begins in
minutes. Using these details, it will have to compute how long the journey will take,
when you’ll arrive at college, and how much time you’ll have left before your class
starts.

INPUT:

5
OUTPUT:

6
2. Python Programs using Conditional Statements

i. Verify if the year is a Leap year


Imagine you’re organizing the “Leap Year Festival,” a fun event that only happens on
February 29th during a leap year. To plan the festival, you need to find out if a year has
this extra day in February. A year is considered a leap year if it is divisible by 4, except
when it is divisible by 100, unless it is also divisible by 400. To make sure your plans are
correct, you need to write a Python program to check if a year is a leap year.

INPUT:

OUTPUT:

ii. Alarm for the weekend


Imagine you have a regular alarm to wake up for school, but you don’t need it on
weekends. You wish to determine whether today is a weekend or a weekday to decide

7
whether you should set the alarm. If it’s the weekend, you get to sleep longer. If it’s a
weekday, you should set the alarm to wake up early. Write a Python program to check if
you need to set an alarm or not.

INPUT:

OUTPUT:

iii. Group Assignment


You are working on a group assignment, and your teacher says that each group member
must contribute a score that meets several criteria to qualify for extra credit. These
criteria are:
The score must be divisible by both 2 and 3.

8
The score must be at least 5.
The score must not be equal to 9.
If the score is prime, it still needs to be divisible by both 2 and 3.
Write a Python program to check if the score qualifies based on these conditions.

INPUT:

OUTPUT:

iv. Securing your online account


You are creating a new account and want to set a strong password to keep it secure. For
the password to be strong, it must follow these simple rules:
It should be at least 8 characters long.
The first character must be an uppercase letter.
The last character must be a lowercase letter.
If your password meets all these rules, it will be accepted as “Strong.” Otherwise, you’ll

9
need to create a better one.
Write a Python program to check if a password is strong based on these rules.

INPUT:

OUTPUT:

10
3. Python Programs using Iterative Statements

i. Reversing ticket number


Imagine you are a lottery organizer. Each lottery ticket has a unique 3-digit number, and
you want to create a special reward code by reversing the digits of the ticket number. For
example, if the ticket number is 123, the reward code will be 321. This reversed number
will be used to determine bonus prizes for the lucky participants. How can you reverse
the digits of a 3-digit lottery ticket number using Python?

INPUT:

OUTPUT:

ii. Decode the hidden message in the number


Imagine you’re a mysterious scribe you’re asked to decode a hidden number message.
To do this, you first take the given number and multiply it by 3. Then, you look at each

11
digit of the resulting number and transform it: if the digit is odd, you increase it by 1 (for
example, 1 becomes 2, 3 becomes 4), and if the digit is even, you decrease it by 1 (for
example, 2 becomes 1, 4 becomes 3). Finally, you add all the transformed digits together
to get the final decoded number, which holds the secret message. Your task is to follow
these steps to figure out the hidden message using Python script!

INPUT:

OUTPUT:

iii. Squid Game found


Imagine you’re a contestant in a tough round of Squid Game. In this game, you start with
a number, and in each round, the number changes. Sometimes, it gets bigger by
multiplying by 2, or it gets bigger by adding a certain value. If the number ever has the
digit “7” in it, you lose and the game ends. But if the number is divisible by 4, you get a
second chance, and the number will be cut in half. Your job is to see how many rounds
you can survive before the number breaks the rules, and count the total rounds it takes

12
for the game to end. Write a Python program that simulates the game and tells you if you
survive each round or not.

INPUT:

OUTPUT:

iv. Water intake Tracker


Do you want to track how much water you drink every day for a week? For that, you
want to know the total amount of water you’ve consumed by the end of the week.
Write a Python program to calculate the total water intake for the week based on how
much you drink each day.

INPUT:

13
OUTPUT:

v. Weekly Grocery Budget


You have a weekly grocery budget of $150. Each time you shop, you enter the cost of
the items purchased. If your spending exceeds your budget, the program warns you. Use
a while loop to track your expenses until you reach the budget limit.

INPUT:

14
OUTPUT:

vi. Magical Potion Brewer


In the kingdom of Azura, a potion maker starts with 5 units of magical herb and 10 units
of moonstone. After each batch, the herb goes down by 1 unit and the moonstone goes
up by 2 units. After the 10th batch, the potion maker adds 3 more units of herb to each
batch to make the potion stronger. The potion maker continues brewing until the total
ingredients used is more than 100. Write a Python program that uses a while loop to
track how many ingredients are used in each batch, shows how much herb and
moonstone is used, and stops when the total ingredients are over 100.

15
INPUT:

OUTPUT:

vii. Pirate Treasure Hunt


You’re the captain of a pirate ship, leading your crew on a treasure hunt. The treasure is
hidden somewhere in a 4×5 grid of sand. To make it exciting, ask a crew member to
secretly pick a row and column for the treasure’s location. Now, you need to check every
spot in the grid. As you search, if you find the treasure at the chosen spot, print “Found
treasure!” For all other spots, print “Try again.” How can you write a Python program
using nested loops to search the grid and find the treasure based on the user’s input for
its location?

16
INPUT:

OUTPUT:

viii. Prime number grid puzzle


Imagine you’re designing a math puzzle for students, where they need to find prime
numbers in a grid. The grid contains numbers generated by multiplying the row and
column indices, and you want to highlight only the prime numbers. To make it easier to
visualize, any number that isn’t prime will be replaced with a dash (-). The goal is to
programmatically create this grid and display it so students can spot the prime numbers.
How can you use nested loops in Python to generate this grid, check if each number is
prime, and print the grid where prime numbers remain, and non-prime numbers are
replaced with a dash (-)?

17
INPUT:

OUTPUT:

ix. Talent show pyramid


Imagine you’re organizing a talent show, and participants need to stand in a pyramid
formation for their final performance. The first row will have 1 person, the second row
will have 2 people, the third row will have 3, and so on, forming a pyramid shape. To
plan this, you decide to create a program that prints a pyramid of numbers, where each
row represents the number of people in that row. The user will specify how many rows
the pyramid should have. Create a Python script to print this pyramid of numbers based
on the user’s input for the number of rows?

INPUT:

18
OUTPUT:

x. Auto-driving cars and traffic signals


Suppose you are developing a system for an autonomous car to navigate through a grid
of streets. Each street has a traffic signal at the intersections, which can be red, yellow, or
green. The car needs to check each intersection in its path. The car can only move
forward when the signal is green. If it’s yellow, the car waits for the light to turn green,
and if it’s red, the car must stop and turn back. Your program has to simulate the car’s
journey through the grid using nested loops

INPUT:

19
OUTPUT:

4. Python Programs using Strings

i. Count the frequency of a character in a string

INPUT:

20
OUTPUT:

ii. Count the frequency of a word in a string

INPUT:

21
OUTPUT:

iii. Longest substring without repeating a character

INPUT:

22
OUTPUT:

iv. Input a string having digits and print the sum of digits present in the
string

INPUT:

OUTPUT:

23
v. Input a string and a character. Delete the occurrence of the character in
the given string.

INPUT:

OUTPUT:

24
1. Python Programs using Lists
i. Weather data analysis
Imagine you are working for a weather forecasting company, and you’ve been
tasked with analyzing the temperatures for a specific month. You have a list
of daily temperatures for that month, and your job is to calculate three key
things: the average temperature for the month, the number of days the
temperature was above average, and the difference between the highest and
lowest temperatures recorded. You need to write a Python program that
performs these calculations and displays the results, so the company can get a
clear understanding of the temperature trends for that month.

INPUT:
OUTPUT:

25
ii. Stock market investment
Imagine you are an investor who invests a fixed amount monthly in the stock
market. You track a company’s stock prices over several months to evaluate
your gains or losses based on percentage changes in the stock prices. A rise or
fall in stock price directly affects your investment, like a 10% increase
yielding a 10% gain. To analyze your performance, you write a Python
program to calculate the monthly percentage change, determine the gain or
loss for each month, and compute the total profit or loss over the period.

INPUT:
OUTPUT:

iii. Freelance earning calculation


As a freelancer, you work on several client projects, each with a different
hourly rate. You track the hours worked for each client. At the end of the
month, you need to calculate your total income based on the hours worked
and the hourly rates for each client.
Write a Python program that takes three inputs: a list of client names, a list of
hours worked, and a list of hourly rates, then calculates and outputs your total
income for the month.

INPUT:
OUTPUT:

iv. Twitter hashtag trending


You are analyzing a set of tweets to find the most frequently used hashtag.
The array of strings represents tweets, and each tweet contains hashtags. You
need to find out which hashtag has the highest frequency across all tweets
using a Python code.

26
INPUT:
OUTPUT:

v. Monster hunt
In a dark forest, you’re hunting monsters. Each monster has a different
health value. Your goal is to calculate how many monsters you can defeat with
your weapon’s attack power. The weapon’s power decreases by 10% after
each attack. You stop when your weapon’s power is zero or less. Write a
Python script to calculate how many monsters you can defeat.

INPUT:
OUTPUT:

vi. Freelance rating


You manage ratings for freelancers. Freelancer ratings are stored in an array,
where each rating is between 0 and 5. A new policy deducts 0.5 from the
rating of each freelancer who hasn’t worked in the last 6 months. Any
freelancer with a rating less than 2 will receive a “Low Priority” tag. Develop
a Python script for this scenario.

INPUT:
OUTPUT:

27
28

You might also like