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

Python Record AI&DS 2023-------Clever (2)

The document is a laboratory record notebook for Rajalakshmi Engineering College, detailing various Python programming exercises. Each exercise includes a problem statement, aim, algorithm, program, output, and result, confirming successful implementation. The exercises cover topics such as input handling, calculations, and conditional statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Record AI&DS 2023-------Clever (2)

The document is a laboratory record notebook for Rajalakshmi Engineering College, detailing various Python programming exercises. Each exercise includes a problem statement, aim, algorithm, program, output, and result, confirming successful implementation. The exercises cover topics such as input handling, calculations, and conditional statements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 130

RAJALAKSHMI ENGINEERING COLLEGE

RAJALAKSHMI NAGAR, THANDALAM - 602 105.

RAJALAKSHMI
ENGINEERING COLLEGE

Laboratory Record Note Book

NAME

BRANCH

UNIVERSITY REGISTER No

COLLEGE ROLL No

SEMESTER

ACADEMIC YEAR
RAJALAKSHMI
ENGINEERING COLLEGE
An AUTONOMOUS lnstttutten
AmMiated to ANNA UNNERSTY, Cherat

BONAFIDE CERTIFICATE

NAME

ACADEMIC YEAR. ..SEMESTER BRANCH..

UNIVERSITY REGISTER No.

Certifieð that this is the bonafide recorò of work done by the above student in the

Laboratory dMring the year 20 - 20

Signature of Faculty - in -Charge

Submitted for the Practical Examination held on..

External Examiner

Internal Examiner
INDEX

Name: Branch: Sec: Roll No:


S.No. Date Title Page No. Teacher's Sign/Remarks
ROLLNO:221801031

EX NO : 1

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that displays the name and complete mailing address as given in sample outputs. Your program
does not need to read any input from the user.

ALGORITHM:

Step 1: Start the program.


Step 2: Define variables to store the name and address information.
Step 3: Assign the name and address values to the variables.
Step 4: Display the name and address using a print statement or any other appropriate method.
Step 5: End the program.

1
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

2
ROLLNO:221801031

EX NO : 2

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that asks the user to enter his or her name. The program should respond with a message that says hello to
the user, using his or her name.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter their name.
Step 3: Read the input from the user and store it in a variable.
Step 4: Construct a greeting message by concatenating the user's name with a predefined greeting phrase.
Step 5: Display the greeting message to the user.
Step 6: End the program.

3
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

4
ROLLNO:221801031

EX NO : 3

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that asks the user to enter the width and length of a room. Once these values have been read, your program
should compute and display the area of the room. The length and the width will be entered as floating-point numbers.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the width of the room.
Step 3: Read the input for the width and store it in a variable.
Step 4: Prompt the user to enter the length of the room.
Step 5: Read the input for the length and store it in a variable.
Step 6: Calculate the area of the room by multiplying the width and length
.
Step 7: Display the calculated area to the user.
Step 8: End the program.

5
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

6
ROLLNO:221801031

EX NO : 4
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads the length and width of a farmer’s field from the user in feet. Display the area of the field in acres.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the length of the field in feet.
Step 3: Read the input for the length and store it in a variable.
Step 4: Prompt the user to enter the width of the field in feet.
Step 5: Read the input for the width and store it in a variable.
Step 6: Calculate the area of the field by multiplying the length and width.
Step 7: Convert the area from square feet to acres by dividing it by 43560 (the number of square feet in an acre).
Step 8: Display the calculated area in acres to the user.
Step 9: End the program.

7
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

8
ROLLNO:221801031

EX NO : 5

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads the number of containers (less and more) of each size from the user. Your program should
continue by computing and displaying the refund that will be received for returning those containers. Format the output so that it
includes a dollar sign and always displays exactly two decimal places.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the number of drink containers holding one liter or less.
Step 3: Read the input for the number of smaller containers and store it in a variable.
Step 4: Prompt the user to enter the number of drink containers holding more than one liter.
Step 5: Read the input for the number of larger containers and store it in a variable.
Step 6: Calculate the refund for the smaller containers by multiplying the number of smaller containers by $0.10.
Step 7: Calculate the refund for the larger containers by multiplying the number of larger containers by $0.25.
Step 8: Add the refund amounts for the smaller and larger containers to get the total refund.
Step 9: Display the total refund amount formatted with a dollar sign and two decimal places.
Step 10: End the program.

9
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

10
ROLL NO: 221801031

EX NO : 6

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that you create for this exercise will begin by reading the cost of a meal ordered at a restaurant
from the user. Then your program will compute the tax and tip for the meal. Use your local tax rate (5 percent) when
computing the amount of tax owing. Compute the tip as 18 percent of the meal amount (without the tax). The output from
your program should include the tax amount, the tip amount, and the grand total for the meal including both the tax and
the tip. Format the output so that all of the values are displayed using two decimal places.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the cost of the meal.
Step 3: Read the input for the meal cost and store it in a variable.
Step 4: Calculate the tax amount by multiplying the meal cost by the tax rate (5 percent).
Step 5: Calculate the tip amount by multiplying the meal cost (without tax) by the tip rate (18 percent).
Step 6: Calculate the grand total by adding the meal cost, tax amount, and tip amount.
Step 7: Display the tax amount, tip amount, and grand total formatted with two decimal places.
Step 8: End the program.

11
ROLL NO: 221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

12
ROLL NO: 221801031

EX NO : 7

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads a positive integer, n, from the user and then displays the sum of all of the integers from 1
to n. The sum of the first n positive integers can be computed using the formula:

sum = ( n ) (n + 1) / 2

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a positive integer, n.
Step 3: Read the input for n and store it in a variable.
Step 4: Calculate the sum of all integers from 1 to n using the formula sum = (n) * (n + 1) / 2.
Step 5: Display the calculated sum to the user.
Step 6: End the program.

13
ROLL NO: 221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

14
ROLL NO: 221801031

EX NO : 8

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads the number of widgets and the number of gizmos from the user. Then
your program should compute and display the total weight of the parts.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the number of widgets.
Step 3: Read the input for the number of widgets and store it in a variable.
Step 4: Prompt the user to enter the number of gizmos.
Step 5: Read the input for the number of gizmos and store it in a variable.
Step 6: Calculate the total weight of widgets by multiplying the number of widgets by the weight per widget (75 grams).
Step 7: Calculate the total weight of gizmos by multiplying the number of gizmos by the weight per gizmo (112 grams).
Step 8: Calculate the total weight of the parts by adding the total weight of widgets and the total weight of gizmos.
Step 9: Display the total weight of the parts to the user.
Step 10: End the program.

15
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

16
ROLLNO:221801031

EX NO : 9
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that begins by reading the amount of money deposited into the account from the user. Then your
program should compute and display the amount in the savings account after 1, 2, and 3 years. Display each amount so that
it is rounded to 2 decimal places.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the amount of money deposited into the savings account.
Step 3: Read the input for the deposit amount and store it in a variable.
Step 4: Initialize a variable to keep track of the current balance and set it equal to the deposit amount.
Step 5: Initialize a variable to represent the interest rate (4 percent).
Step 6: Initialize a variable to represent the number of years.
Step 7: Loop through each year from 1 to 3 (or any desired number of years).
Step 7.1: Calculate the interest earned by multiplying the current balance by the interest rate divided by 100.
Step 7.2: Add the interest earned to the current balance.
Step 7.3: Display the current balance rounded to 2 decimal places.
Step 8: End the program.

17
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

18
ROLLNO:221801031

EX NO : 10

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads two integers, a and b, from the user. Your program should compute and display:
• The sum of a and b
• The difference when b is subtracted from a
• The product of a and b
• The quotient when a is divided by b
• The remainder when a is divided by b

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the value of integer a.
Step 3: Read the input for a and store it in a variable.
Step 4: Prompt the user to enter the value of integer b.
Step 5: Read the input for b and store it in a variable.
Step 6: Calculate the sum of a and b.
Step 7: Display the calculated sum to the user.
Step 8: Calculate the difference when b is subtracted from a.
Step 9: Display the calculated difference to the user.
Step 10: Calculate the product of a and b.
Step 11: Display the calculated product to the user.
Step 12: Calculate the quotient when a is divided by b.
Step 13: Display the calculated quotient to the user.
Step 14: Calculate the remainder when a is divided by b.
Step 15: Display the calculated remainder to the user.
Step 16: End the program.

19
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

20
ROLLNO:221801031

EX NO : 11

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads an integer from the user. Then your program should display a message
indicating whether the integer is even or odd.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter an integer.
Step 3: Read the input for the integer and store it in a variable.
Step 4: Check if the integer is divisible by 2 (i.e., if the remainder when divided by 2 is 0).
If the remainder is 0, go to Step 5.
If the remainder is not 0, go to Step 6.
Step 5: Display a message indicating that the integer is even.
Step 6: Display a message indicating that the integer is odd.
Step 7: End the program.

21
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

22
ROLLNO:221801031

EX NO : 12

DATE :

PROBLEM STATEMENT:

AIM:
To write a python program that reads a letter of the alphabet from the user. If the user enters a, e, i, o or u then your program should
display a message indicating that the entered letter is a vowel. If the user enters y then your program should display a message
indicating that sometimes y is a vowel, and sometimes y is a consonant. Otherwise your program should display a message
indicating that the letter is a consonant.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a letter of the alphabet.
Step 3: Read the input for the letter and store it in a variable.
Step 4: Check if the letter is 'a', 'e', 'i', 'o', or 'u'.
If the letter is any of those vowels, go to Step 5.
If the letter is not any of those vowels, go to Step 6.
Step 5: Display a message indicating that the entered letter is a vowel.
Step 6: Check if the letter is 'y'.
If the letter is 'y', go to Step 7.
If the letter is not 'y', go to Step 8.
Step 7: Display a message indicating that sometimes y is a vowel and sometimes y is a consonant.
Step 8: Display a message indicating that the letter is a consonant.
Step 9: End the program.

23
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

24
ROLLNO:221801031

EX NO : 13

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that determines the name of a shape from its number of sides. Read the number of sides from the user and
then report the appropriate name as part of a meaningful message. Your program should support shapes with anywhere from 3 up to
(and including) 10 sides. If a number of sides outside of this range is entered then your program should display an appropriate error
message.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the number of sides of a shape.
Step 3: Read the input for the number of sides and store it in a variable.
Step 4: Check if the number of sides is within the range of 3 to 10 (inclusive).
If the number of sides is within the range, go to Step 5.
If the number of sides is outside the range, go to Step 8.
Step 5: Determine the name of the shape based on the number of sides using a conditional statement or a switch case:
For 3 sides, the shape is a triangle.
For 4 sides, the shape is a quadrilateral.
For 5 sides, the shape is a pentagon.
For 6 sides, the shape is a hexagon.
For 7 sides, the shape is a heptagon.
For 8 sides, the shape is an octagon.
For 9 sides, the shape is a nonagon.
For 10 sides, the shape is a decagon.
Step 6: Display the name of the shape to the user.
Step 7: Display an error message indicating that the entered number of sides is invalid.
Step 8: End the program.

25
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

26
ROLLNO:221801031

EX NO : 14
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads the lengths of the three sides of a triangle from the user. Then display a
message that states the triangle’s type.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the length of the first side of the triangle.
Step 3: Read the input for the length of the first side and store it in a variable.
Step 4: Prompt the user to enter the length of the second side of the triangle.
Step 5: Read the input for the length of the second side and store it in a variable.
Step 6: Prompt the user to enter the length of the third side of the triangle.
Step 7: Read the input for the length of the third side and store it in a variable.
Step 8: Check the lengths of the sides to determine the type of triangle:
If all three sides have the same length, display a message indicating that it is an equilateral triangle.
If two sides have the same length and the third side has a different length, display a message indicating that it is an isosceles triangle.
If all three sides have different lengths, display a message indicating that it is a scalene triangle.
Step 9: End the program.

27
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

28
ROLLNO:221801031

EX NO : 15

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads a year from the user and displays a message indicating whether or not it is a leap
year.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a year.
Step 3: Read the input for the year and store it in a variable.
Step 4: Check if the year is divisible by 400.
If it is divisible by 400, go to Step 5.If not, go to Step 6.
Step 5: Display a message indicating that the year is a leap year.
Step 6: Check if the year is divisible by 100.If it is divisible by 100, go to Step 7. If not, go to Step 8.
Step 7: Display a message indicating that the year is not a leap year.
Step 8: Check if the year is divisible by 4.If it is divisible by 4, go to Step 9.If not, go to Step 10.
Step 9: Display a message indicating that the year is a leap year.
Step 10: Display a message indicating that the year is not a leap year.
Step 11: End the program.

29
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

30
ROLLNO:221801031

EX NO : 16

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads the name of a month from the user as a string. Then your program should display the
number of days in that month. Display “28 or 29 days” for February so that leap years are addressed.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the name of a month.
Step 3: Read the input for the month and store it in a variable.
Step 4: Check if the month is "February".If it is "February", go to Step 5.If not, go to Step 6.
Step 5: Display a message indicating that February has "28 or 29 days".
Step 6: Check if the month is any of the months with 30 days (April, June, September, November).
If it is any of those months, go to Step 7.
If not, go to Step 8.
Step 7: Display a message indicating that the month has "30 days".
Step 8: Display a message indicating that the month has "31 days".
Step 9: End the program.

31
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

32
ROLLNO:221801031

EX NO : 17

DATE :

PROBLEM STATEMENT:

AIM:
To write a python program that implements the conversion from human years to dog years described in the previous paragraph. Ensure
that your program works correctly for conversions of less than two human years and for conversions of two or more human years. Your
program should display an appropriate error message if the user enters a negative number.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the number of human years.
Step 3: Read the input for the number of human years and store it in a variable.
Step 4: Check if the number of human years is negative.
If it is negative, display an error message indicating that the input is invalid and go to Step 9.
If not, continue to the next step.
Step 5: Check if the number of human years is less than 2.
If it is less than 2, go to Step 6.
If not, go to Step 7.
Step 6: Calculate the dog years by multiplying the number of human years by 10.5.
Display the calculated dog years to the user.
Go to Step 9.
Step 7: Subtract 2 from the number of human years and store the result in a variable.

33
ROLLNO:221801031

Step 8: Calculate the dog years for the first two human years (10.5 dog years each) and for the remaining human years (4 dog years each).
Multiply 2 by 10.5 and add it to the product of the remaining human years multiplied by 4.
Display the calculated dog years to the user.
Step 9: End the program.

34
ROLLNO:221801031
PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

35
ROLLNO:221801031

EX NO : 18

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads a year from the user and displays the animal associated with that year. Your program should
work correctly for any year greater than or equal to zero, not just the ones listed in the table.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a year.
Step 3: Read the input for the year and store it in a variable.
Step 4: Calculate the remainder when the year is divided by 12.
Store the remainder in a variable.
Step 5: Use a switch case or if-else statements to determine the animal associated with the year based on the remainder:
If the remainder is 0, display "Dragon" as the associated animal.
If the remainder is 1, display "Snake" as the associated animal.
If the remainder is 2, display "Horse" as the associated animal.
If the remainder is 3, display "Sheep" as the associated animal.
If the remainder is 4, display "Monkey" as the associated animal.
If the remainder is 5, display "Rooster" as the associated animal.
If the remainder is 6, display "Dog" as the associated animal.
If the remainder is 7, display "Pig" as the associated animal.
If the remainder is 8, display "Rat" as the associated animal.
If the remainder is 9, display "Ox" as the associated animal.
If the remainder is 10, display "Tiger" as the associated animal.
If the remainder is 11, display "Hare" as the associated animal.
If the remainder is none of the above, display an error message indicating that the year is invalid.
Step 6: End the program.

36
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

37
ROLLNO:221801031

EX NO : 19

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads a rating from the user and indicates whether the performance for that rating is unacceptable,
acceptable or meritorious. The amount of the employee’s raise should also be reported. Your program should display an appropriate
error message if an invalid rating is entered.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a rating.
Step 3: Read the input for the rating and store it in a variable.
Step 4: Check if the rating is equal to 0.0.
a. If true, display a message indicating that the performance is unacceptable.
b. Calculate the raise amount by multiplying $2,400.00 by the rating.
c. Display the raise amount to the user.
Step 5: Check if the rating is equal to 0.4.
a. If true, display a message indicating that the performance is acceptable.
b. Calculate the raise amount by multiplying $2,400.00 by the rating.
c. Display the raise amount to the user.
Step 6: Check if the rating is greater than or equal to 0.6.
a. If true, display a message indicating that the performance is meritorious.
b. Calculate the raise amount by multiplying $2,400.00 by the rating.
c. Display the raise amount to the user.
Step 7: If none of the above conditions are met, display an error message indicating that the entered rating is invalid.
Step 8: End the program.

38
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

39
ROLLNO:221801031

EX NO : 20

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program to check the given input is key word or not.

ALGORITHM:

Step 1: Start the program.


Step 2: Initialize the set of keywords with the provided keywords: {break, case, continue, default, defer, else, for, func, goto, if, map,
range, return, struct, type, var}.
Step 3: Prompt the user to enter a word.
Step 4: Read the input word and store it in a variable.
Step 5: Check if the input word is present in the set of keywords.
a. If true, display a message indicating that the input word is a keyword.
b. If false, display a message indicating that the input word is not a keyword.
Step 6: End the program.

40
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

41
ROLLNO:221801031

EX NO : 21
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that computes the average of a collection of values entered by the user. The user will enter 0 as a
sentinel value to indicate that no further values will be provided. Your program should display an appropriate error message if
the first value entered by the user is 0.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a value.
Step 3: Read the input value and store it in a variable.
Step 4: Check if the input value is 0.
a. If true, display an error message indicating that the first value cannot be 0 and go to Step 9.
Step 5: Initialize a variable to keep track of the sum of the values and set it to 0.
Step 6: Initialize a variable to keep track of the count of values and set it to 0.
Step 7: Repeat the following steps until the user enters 0 as the sentinel value:
a. Add the input value to the sum.
b. Increment the count of values by 1.
c. Prompt the user to enter the next value.
d. Read the input value and store it in a variable.
Step 8: Check if the count of values is 0.
a. If true, display an error message indicating that no values were entered and go to Step 9.
Step 9: Calculate the average by dividing the sum of values by the count of values.
Step 10: Display the calculated average to the user.
Step 11: End the program.

42
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

43
ROLLNO:221801031

EX NO : 22

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that uses a loop to generate this table, showing the original price, the discount amount, and the
new price for purchases of $4.95, $9.95, $14.95, $19.95 and $24.95. Ensure that the discount amounts and the new prices are
rounded to 2 decimal places when they are displayed.

ALGORITHM:

Step 1: Start the program.


Step 2: Create a list of purchase prices: [$4.95, $9.95, $14.95, $19.95, $24.95].
Step 3: Loop through each purchase price in the list.
a. For each purchase price, calculate the discount amount by multiplying it by 0.6 (60 percent).
b. Calculate the new price by subtracting the discount amount from the original price.
c. Display the original price, discount amount, and new price for the current purchase price.
- Round the discount amount and new price to 2 decimal places before displaying.
Step 4: End the program.

44
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

45
ROLL NO: 221801031

EX NO : 23

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should
include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate
headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the Internet.

ALGORITHM:

Step 1: Start the program.


Step 2: Print the table heading with column labels for Celsius and Fahrenheit temperatures.
Step 3: Loop through each temperature in the range of 0 to 100 degrees Celsius, with increments of 10 degrees Celsius.
a. Inside the loop, convert the Celsius temperature to Fahrenheit using the formula: Fahrenheit = (Celsius * 9/5) + 32.
b. Print the Celsius temperature and its corresponding Fahrenheit temperature in the table.
Step 4: End the program.

46
ROLL NO: 221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

47
ROLL NO: 221801031

EX NO : 24

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program to find the count of ALL digits in a given number N. The number will be passed to the program as
an input of type int.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a positive integer number (N).
Step 3: Read the input number (N) and store it in a variable.
Step 4: Initialize a variable (count) to 0, which will keep track of the count of digits.
Step 5: Convert the input number (N) to a string to easily iterate over its digits.
Step 6: Loop through each character (digit) in the string representation of N.
a. For each digit, increment the count variable by 1.
Step 7: Display the count of digits to the user.
Step 8: End the program.

48
ROLL NO: 221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

49
ROLL NO: 221801031

EX NO : 25

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program to determine the factors of a number (i.e., all positive integer values that evenly divide into a number).

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a positive integer number.
Step 3: Read the input number and store it in a variable.
Step 4: Initialize an empty list to store the factors of the number.
Step 5: Loop through each integer from 1 to the input number (inclusive).
a. Check if the current number divides the input number evenly (i.e., the input number modulo the current number is 0).
b. If it does, add the current number to the list of factors.
Step 6: Display the list of factors to the user.
Step 7: End the program.

50
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

51
ROLLNO:221801031

EX NO : 26
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program to return the nth number in the fibonacci series.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the value of n.
Step 3: Read the input for n and store it in a variable.
Step 4: Initialize two variables, 'a' and 'b', with the initial values of 0 and 1 respectively.
Step 5: If n is less than or equal to 0, display an error message and end the program.
Step 6: If n is equal to 1, display the value of 'a' and end the program.
Step 7: If n is equal to 2, display the value of 'b' and end the program.
Step 8: Initialize a variable 'count' to 2 to represent the current position in the Fibonacci series.
Step 9: Start a loop that continues until 'count' reaches n:
a. Calculate the next Fibonacci number by adding 'a' and 'b' and store it in a variable 'next_number'.
b. Update the values of 'a' and 'b' by assigning 'b' to 'a' and 'next_number' to 'b'.
c. Increment 'count' by 1.
Step 10: Display the value of 'b' as the nth number in the Fibonacci series.
Step 11: End the program.

52
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

53
ROLLNO:221801031

EX NO : 27

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program to print number is Disarium or not.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a positive integer number.
Step 3: Read the input number and store it in a variable.
Step 4: Convert the number to a string to access its individual digits.
Step 5: Initialize a variable 'sum' to 0 to store the sum of digit raised to the power of their respective positions.
Step 6: Iterate over each digit and its corresponding position in the number.
a. Calculate the power of the digit by raising it to the power of its position.
b. Add the calculated power to the 'sum' variable.
Step 7: Check if the 'sum' is equal to the input number.
a. If it is, display a message indicating that the number is a Disarium number.
b. If it is not, display a message indicating that the number is not a Disarium number.
Step 8: End the program.

54
ROLLNO:221801031
PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

55
ROLLNO:221801031

EX NO : 28

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that returns the second last digit of the given number. Second last digit is being referred 10the digit in
the tens place in the given number.

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a number.
Step 3: Read the input number and store it in a variable.
Step 4: Convert the number to a string to access its individual digits.
Step 5: Check if the length of the string representation of the number is less than or equal to 1.
a. If it is, return -1 to indicate that the second last digit does not exist.
Step 6: Extract the second last digit by accessing the character at index -2 from the string.
a. If the second last digit is negative, convert it to a positive number.
Step 7: Return the second last digit.
Step 8: End the program.

56
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

57
ROLLNO:221801031

EX NO : 29

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program for printing all the prime numbers between the given interval (or range).

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter the lower value of the interval.
Step 3: Read the input for the lower value and store it in a variable.
Step 4: Prompt the user to enter the upper value of the interval.
Step 5: Read the input for the upper value and store it in a variable.
Step 6: Print a message indicating that all prime numbers between the given interval will be displayed.
Step 7: Initialize an empty list to store the prime numbers.
Step 8: Iterate through each number in the interval (from lower value to upper value, inclusive).
a. Check if the current number is greater than 1.
b. If it is, iterate through each number from 2 to the square root of the current number (rounded up).
i. Check if the current number is divisible by any of the numbers in the range.
ii. If it is, break the loop.
c. If the loop completed without finding any divisors, add the current number to the list of prime numbers.
Step 9: Print the list of prime numbers.
Step 10: End the program.

58
ROLLNO:221801031
PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

59
ROLLNO:221801031

EX NO : 30

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program print the following pattern

ALGORITHM:

Step 1: Start the program.


Step 2: Prompt the user to enter a number.
Step 3: Read the input number and store it in a variable.
Step 4: Iterate from 1 to the input number (inclusive).
a. Within the outer loop, iterate from 1 to the current number (inclusive).
b. Print the current number in each iteration of the inner loop, separated by a space.
c. Print a new line after each iteration of the outer loop.
Step 5: End the program.

60
ROLL NO:221801031
PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

61
ROLL NO:221801031

EX NO : 31
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for determining a string in palindrome. considering only alphanumeric characters and ignoring
cases

ALGORITHM:

Step 1. Remove all non-alphanumeric characters from the string: Iterate


through each character in the string and check if it is alphanumeric (a
letter or a digit). If a character is not alphanumeric, remove it from the
string.
Step 2. Convert the string to lowercase: Convert all remaining characters in
the string to lowercase. This step is necessary to ignore the case when
checking for palindromes.
Step 3. Check for palindrome: Compare the characters at corresponding
positions in the string. Start from the first and last characters, then
move towards the center, comparing each pair of characters. If any
pair of characters doesn't match, the string is not a palindrome. If all
pairs of characters match, the string is a palindrome.

62
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

63
ROLL NO:221801031

EX NO : 32

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for python program to get one string and reverses the string. the given string is an array of characters
char []

ALGORITHM:

Step 1:Accept the input string as an array of characters.

Step 2: Initialize two pointers, start and end, pointing to the first
and last elements of the array, respectively.

Step 3: Swap the characters at the start and end positions.

Step 4: Increment the start pointer and decrement the end pointer.

Step 5: Repeat steps 3 and 4 until the start pointer becomes


greater than or equal to the end pointer.

Step 6: Convert the array of characters back to a string.

Step 7: Return the reversed string.

64
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

65
ROLL NO:221801031

EX NO : 33

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a program that determines the name of a shape from its number of sides. Read the number of
sides from the user and then report the appropriate name as part of a meaningful message. Your program should support
shapes with anywhere from 3 up to (and including) 10 sides. If a number of sides outside of this range is entered then your
program should display an appropriate error message

ALGORITHM:

Step 1 : Read the number of sides from the user

Step 2: Check if the number of sides is within the range of 3 to 10


(inclusive).If the number is within the range, continue to the next
step.
If the number is less than 3 or greater than 10, display an error
message indicating that the input is outside the supported range.
End the program.

Step 3 : Map the number of sides to the corresponding shape


name.
Use a dictionary to map each number of sides to its
corresponding shape name.
For example: {3: "Triangle", 4: "Quadrilateral", 5: "Pentagon", ...}.

Step 4: Retrieve the shape name from the dictionary using the
input number of sides.
If the number of sides is found in the dictionary, retrieve the
corresponding shape name.
If the number of sides is not found in the dictionary, display an
error message indicating that the shape name is unknown. End
the program.

Step 5: Display a meaningful message indicating the shape name


based on the input number of sides.

66
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

67
ROLL NO:221801031

EX NO : 34

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for In a particular jurisdiction, older license plates consist of three uppercase letters followed by three
digits. When all of the license plates following that pattern had been used, the format was changed to four digits followed by
three uppercase letters.
Write a program that begins by reading a string of characters from the user. Then your program should display a message
indicating whether the characters are valid for an older style license plate or a newer style license plate. Your program should
display an appropriate message if the string entered by the user is not valid for either style of license
Date.

ALGORITHM:

Step 1 : Read a string of characters from the user.

Step 2 : Check the length of the string.


If the length is 6 and the first three characters are uppercase
letters and the last three characters are digits, it is valid for an
older style license plate.
If the length is 7 and the first four characters are digits and the
last three characters are uppercase letters, it is valid for a newer
style license plate.
If the length is not 6 or 7, display an error message indicating that
the string is not valid for either style of license plate. End the
program.

Step 3 : Display a message indicating the license plate style based


on the format determined in Step 2.

68
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

69
ROLL NO:221801031

EX NO : 35

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a program that takes as input a string (sentence), and returns its second word in uppercase.
For example:
If input is "Wipro Technologies Bangalore" the function should return 'TECHNOLOGIES"

ALGORITHM:

Step 1 : Read a string (sentence) from the user.

Step 2 : Split the sentence into words.

Step 3 : Check if the number of words in the sentence is at least two.


If the number of words is less than two, display an error message indicating that the sentence does not have a second word.
End the program
.
Step 4 : Get the second word from the list of words.

Step 5 : Convert the second word to uppercase.

Step 6 : Return the uppercase second word.

70
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

71
ROLL NO:221801031

EX NO : 36
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a code to reverse the case of a character input
Input Format:
Single character Input
Output Format:
Reversed character

ALGORITHM:

Step 1 : Read a single character input.

Step 2 : Check if the character is uppercase.


If the character is uppercase, convert it to lowercase
.
Step 3 : Check if the character is lowercase.
If the character is lowercase, convert it to uppercase.

Step 4 : Display the reversed character.

72
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

73
ROLL NO:221801031

EX NO : 37

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Given a strings containing just the characters '('. '). ''. 'y'. 'I' and J', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Constraints:
1 <= s.length <= 10^4 s consists of parentheses only '0010'

ALGORITHM:

Step 1 : Read the input string.

Step 2 : Create an empty stack to store opening brackets.

Step 3 : Iterate through each character in the input string.


If the character is an opening bracket ('(', '[', or '{'), push it onto the stack.
If the character is a closing bracket (')', ']', or '}'):
Check if the stack is empty. If it is, return False, as there is no corresponding opening bracket.
Pop the topmost element from the stack.
Check if the popped opening bracket matches the closing bracket. If they don't match, return False.

Step 4 : After iterating through all characters, check if the stack is empty. If it is not, return False, as there are unclosed opening
brackets.

Step 5 : If the stack is empty and all opening brackets have been correctly closed, return True.

74
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

75
ROLL NO:221801031

EX NO : 38

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
Given a balanced strings, split it in the maximum amount of balanced strings.
Return the maximum amount of split balanced strings

ALGORITHM:

Step 1 : Read the input string.

Step 2 : Initialize a count variable to keep track of the number of balanced strings.

Step 3 : Initialize two counters, left_count and right_count, to track the number of 'L' and 'R' characters encountered.
Step 4 : Iterate through each character in the input string.
If the character is 'L', increment the left_count counter.
If the character is 'R', increment the right_count counter.
If the left_count and right_count are equal, it means we have encountered an equal number of 'L' and 'R' characters, forming
a balanced string.
Increment the count variable by 1.
Reset both left_count and right_count to 0.

Step 5 : Return the count variable, which represents the maximum number of split balanced strings.

76
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

77
ROLL NO:221801031

EX NO : 39

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false

ALGORITHM:

Step 1 : Read the input string.

Step 2 : Initialize a set, alphabet_set, to store the unique lowercase letters encountered.

Step 3 : Iterate through each character in the input string.


If the character is a lowercase letter, add it to the alphabet_set.

Step 4 : Check if the size of the alphabet_set is equal to 26.


If it is, return True, as all 26 lowercase letters have been encountered.
If it is not, return False, as not all 26 lowercase letters have been encountered.

78
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

79
ROLL NO:221801031

EX NO : 40

DATE :

PROBLEM STATEMENT:

AIM:

To write algorithm for Write a program that reads integers from the user and stores them in a list. Your program should
continue reading values until the user enters 0. Then it should display all of the values entered by the user (except for the 0) in
ascending order, with one value appearing on each line. Use either the sort method or the sorted function to sort the list

ALGORITHM:

Step 1 : Create an empty list to store the integers.

Step 2 : Read an integer from the user.

Step 3 : While the entered integer is not equal to 0:


Append the integer to the list.
Read the next integer from the user.

Step 4 : Remove the 0 from the list, if present.

Step 5 : Sort the list in ascending order using the sort method or the sorted function.

Step 6 : Iterate through each value in the sorted list.


Print the value on a separate line.

Step 7 : End the program.

80
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

81
ROLL NO:221801031

EX NO : 41
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a program that reads integers from the user and stores them in a list. Use 0 as a sentinel value to
mark the end of the input. Once all of the values have been read your program should display them (except for the 0) in reverse
order, with one value appearing on each line

ALGORITHM:

Step 1 : Create an empty list to store the integers.

Step 2 : Read an integer from the user.

Step 3 : While the entered integer is not equal to 0:


Append the integer to the list.
Read the next integer from the user.

Step 4 : Remove the 0 from the list, if present.

Step 5 : Reverse the order of the list using the reverse method.

Step 6 : Iterate through each value in the reversed list.


Print the value on a separate line.

Step 7 : End the program.

82
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

83
ROLL NO:221801031

EX NO : 42

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for In this exercise, you will create a program that reads words from the user until the user enters a blank
line. After the user enters a blank line your program should display each word entered by the user exactly once. The words
should be displayed in the same order that they were first entered. For example, if the user enters:
first
second
first
third
second
then your program should display:
first
second
third

ALGORITHM:

Step 1 : Create an empty list to store the words.


Step: Read a word from the user.

Step 2 : While the entered word is not blank (empty string):


Append the word to the list.
Read the next word from the user.

Step 3 : Create a set from the list to remove duplicate words while preserving the order.

Step 4 : Iterate through each word in the set.


Print the word.

Step 5 : End the program.

84
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

85
ROLL NO:221801031

EX NO : 43

DATE :

PROBLEM STATEMENT:

AIM:
To write an algorithm for Create a program that reads integers from the user until a blank line is entered. Once all of the integers have been
read your program should display all of the negative numbers, followed by all of the zeros, followed by all of the positive numbers. within each
group the numbers should be displayed in the same order that they were entered by the user. For example, if the user enters the values 3, -4, 1,
0, -1, 0, and -2 then your program should output the values -4, -1, -2, 0, 0, 3, and 1. Your program should display each value on its own line

ALGORITHM:

Step 1 : Create three empty lists: negatives, zeros, and positives.

Step 2 : Read an integer from the user.

Step 3 : While the entered integer is not a blank line:


If the integer is less than 0, append it to the negatives list.
If the integer is equal to 0, append it to the zeros list.
If the integer is greater than 0, append it to the positives list.
Read the next integer from the user.

Step 4 : Concatenate the negatives, zeros, and positives lists in that order.

Step 5 : Iterate through each number in the concatenated list.


Print the number on a separate line.

Step 6 : End the program.

86
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

87
ROLL NO:221801031

EX NO : 44

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for An integer, n, is said to be perfect when the sum of all of the proper divisors of n is equal to n. For
example, 28 is a perfect
number because its proper divisors are 1, 2, 4, 7 and 14, and 1 + 2 + 4 + 7 + 14 = 28.
If the given number is a perfect number then your program will return True. Otherwise it will return False.

ALGORITHM:

Step 1 : Read the input number, n.

Step 2 : Initialize a variable, sum_of_divisors, to 0.

Step 3 : Iterate from 1 to n/2 (inclusive) using a loop variable, divisor.


If n is divisible by divisor without remainder, add divisor to sum_of_divisors.

Step 4 : Check if sum_of_divisors is equal to n.


If they are equal, return True as the number is a perfect number.
If they are not equal, return False as the number is not a perfect number.

Step 5 : End the program.

88
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

89
ROLL NO:221801031

EX NO : 45

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Assuming that we have some email addresses in the "[email protected]" format, please
write program to print the company name of a given email address. Both user names and company names are composed of letters
only

ALGORITHM:

Step 1 : Read the email address from the user.

Step 2 : Find the index of the "@" symbol in the email address.

Step 3 : Extract the substring after the "@" symbol until the end of the email address.

Step 4 : Print the extracted substring as the company name.

Step 5 : End the program.

90
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

91
ROLL NO:221801031

EX NO : 46
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for You have to generate the sum of specific numbers based on its position in the array set provided to you.

ALGORITHM:

Step 1 : Read the array of numbers from the user.

Step 2 : Initialize a variable, sum, to 0.

Step 3 : Iterate through each element, num, in the array.


Calculate the sum of num multiplied by its position in the array (position starts from 1).
Add the calculated sum to the variable sum.

Step 4 : Print the final sum.

Step 5 : End the program.

92
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

93
ROLL NO:221801031

EX NO : 47

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Create different types of tuples as per below mentioned values and print the same.
()
(1, 2, 3)
(1. 'REC'. 3.4)
('Python', [8, 4, 6], (1, 2, 3))

ALGORITHM:

Step 1 : Create a tuple with the values (1, 2, 3).

Step 2 : Print the tuple.

Step 3 : Create a tuple with the values (1, 'REC', 3.4).

Step 4 : Print the tuple.

Step 5 : Create a tuple with the values ('Python', [8, 4, 6], (1, 2, 3)).

Step 6 : Print the tuple.

Step 7 : End the program.

94
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

95
ROLL NO:221801031

EX NO : 48

DATE :

PROBLEM STATEMENT:

AIM:
To write an algorithm for Create a tuple:
my_tuple =('R'/'a', j'a', l''a','K''s','h','m', i')
and apply slicing and display the output as shown below:
('R', 'a', 'j', 'a')
('l', 'a', 'k', 's', 'h', 'm', 'i")
('R', 'a', 'j')
('I'. 'a'. 'k')
('m', 'I')
ALGORITHM:

Step 1 : Create a tuple with the values ('R', 'a', 'j', 'a', 'l', 'a', 'k', 's', 'h', 'm', 'i').

Step 2 : Apply slicing to extract the elements and create new tuples as per the desired output.

Step 3 : Print the new tuples.

Step 4 : End the program

96
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

97
ROLL NO:221801031

EX NO : 49

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Create a tuple t1 with numbers 1 to 5, t2 with 6 to 10 and t3 with a string "REC".
Concatenate t1 and t2 and print the result.
Repeat the t3 10 times without using any looping statements.
Expected output:
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
('REC', 'REC', 'REC', 'REC', 'REC', 'REC', 'REC', 'REC', 'REC', 'REC')

ALGORITHM:

Step 1 : Create a tuple t1 with numbers 1 to 5.

Step 2 : Create a tuple t2 with numbers 6 to 10.

Step 3 : Create a tuple t3 with a string "REC".

Step 4 : Concatenate t1 and t2 to create a new tuple concatenated_tuple.

Step 5 : Print concatenated_tuple.

Step 6 : Repeat the string in t3 ten times and create a new tuple repeated_tuple.

Step 7 : Print repeated_tuple.

Step 8 : End the program.

98
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

99
ROLL NO:221801031

EX NO : 50

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a python program to read a string and a character, print the number of occurrence of the
character in the string and the location of the first occurrence.
Note: To convert an input string to tuple use tuple(variablename).

ALGORITHM:

Step 1 : Read a string from the user and assign it to a variable input_string.

Step 2 : Read a character from the user and assign it to a variable character.

Step 3 : Convert the input string into a tuple using the tuple() function and assign it to a variable string_tuple.

Step 4 : Initialize a variable count to 0 to keep track of the number of occurrences.

Step 5 : Initialize a variable first_occurrence to None to store the location of the first occurrence.

Step 6 : Iterate over each character c in the string tuple.


If c is equal to the character:
Increment count by 1.
If first_occurrence is None, assign the current index to first_occurrence.

Step 7 : Print the number of occurrences of the character by printing the value of count.

Step 8 : Print the location of the first occurrence by printing the value of first_occurrence.

Step 9 : End the program.

100
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

101
ROLL NO:221801031

EX NO : 51
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Write a program to read a string and a character and find the whether the character is available in the
string or not. Print True if the character is present in the string, False otherwise.

ALGORITHM:

Step 1 : Read a string from the user and assign it to a variable input_string.

Step 2 : Read a character from the user and assign it to a variable character.

Step 3 : Initialize a variable found to False to indicate whether the character is found in the string.

Step 4 : Iterate over each character c in the input string.


If c is equal to the character:
Set found to True.
Break out of the loop.

Step 5 : Print the value of found.

Step 6 : End the program.

102
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

103
ROLL NO:221801031

EX NO : 52

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Given a sorted linked list, delete all duplicates such that each element appear only once.

ALGORITHM:

Step 1 : Initialize a pointer current to the head of the linked list.

Step 2 : Traverse the linked list until the end of the list (i.e., current is not None).

Step 3 : Inside the loop, check if the value of current is equal to the value of its next node (i.e., current.next).
If they are equal, update the next pointer of current to skip the duplicate node (i.e., current.next = current.next.next).
If they are not equal, move current to the next node (i.e., current = current.next).

Step 4 : Return the head of the modified linked list.

Step 5 : End the algorithm.

104
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

105
ROLL NO:221801031

EX NO : 53

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Given two lists, print all the common element of two lists.

ALGORITHM:

Step 1 : Initialize an empty list common_elements to store the common elements.

Step 2 : Iterate over each element x in the first list.

Step 3 : Check if x is present in the second list.


If x is in the second list and not already in common_elements, add x to common_elements.

Step 4 : Print the elements in common_elements.

Step 5 : End the program.

106
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

107
ROLL NO:221801031

EX NO : 54

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm to take a complete sentence as an input and remove duplicate word in it and print (sorted order), then
count all the words which have a length greater than 3 and print.

ALGORITHM:

Step 1 : Read a sentence from the user and assign it to a variable input_sentence.

Step 2 : Split the sentence into a list of words using whitespace as the delimiter and assign it to a variable words.

Step 3 : Initialize an empty set unique_words to store unique words.

Step 4 : Iterate over each word word in words.


Add word to the unique_words set.

Step 5 : Convert the unique_words set back into a list and sort it in alphabetical order, assigning it to a variable sorted_words.

Step 6 : Print the sorted words.

Step 7 : Initialize a variable count to 0 to keep track of the words with a length greater than 3.

Step 8 : Iterate over each word word in sorted_words.


If the length of word is greater than 3, increment count by 1.

Step 9 : Print the value of count.

Step 10 : End the program.

108
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

109
ROLL NO:221801031

EX NO : 55

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Create a program that determines and displays the number of unique characters in a string entered by
the user. For example. Hello. World! has 10 unique characters while zzz has onlv one unique character. Use a dictionary or set to
solve this problem.

ALGORITHM:

Step 1 : Read a string from the user and assign it to a variable input_string.

Step 2 : Initialize an empty set unique_characters to store unique characters.

Step 3 : Iterate over each character char in input_string.


Add char to the unique_characters set.

Step 4 : Print the number of unique characters, which is the length of the unique_characters set.

Step 5 : End the program.

110
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

111
ROLL NO:221801031

EX NO : 56
DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for Two words are anagrams if they contain all of the same letters, but in a different order. For example,
"evil" and live" are anagrams because each contains one "e", one "¡", one "", and one "v". Create a program that reads two
strings from the user, determines whether or not they are anagrams, and reports the result.

ALGORITHM:

Step 1 : Read two strings from the user and assign them to variables string1 and string2.

Step 2 : Convert both strings to lowercase to ignore case sensitivity.

Step 3 : Remove any whitespace from both strings.

Step 4 : Sort both strings alphabetically.

Step 5 : If the sorted strings are equal, then the strings are anagrams.

Step 6 : Print the result, either "The strings are anagrams" or "The strings are not anagrams".

Step 7 : End the program.

112
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

113
ROLL NO:221801031

EX NO : 57

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for In the game of Scrabble™, each letter has points associated with it. The total score of a
word is the sum of the scores of its letters. More common letters are worth fewer points while less common letters are
worth more points.

ALGORITHM:

Step 1 : Create a dictionary to store the points associated with each letter. Initialize it with the points for each letter.
For example: letter_scores = {'A': 1, 'B': 3, 'C': 3, ...}

Step 2 : Read a word from the user and assign it to a variable word.

Step 3 : Initialize a variable total_score to 0, which will store the cumulative score of the word.

Step 4 : Convert the word to uppercase to ignore case sensitivity.

Step 5 : Iterate over each letter letter in the word.


If letter exists in the letter_scores dictionary, add its corresponding score to total_score.

Step 6 : Print the total_score of the word.

Step 7 : End the program.

114
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

115
ROLL NO:221801031

EX NO : 58

DATE :

PROBLEM STATEMENT:

AIM:

To write an algorithm for You are given an array of N integers, A1, A2, . .., AN and an integer K. Return the of count of distinct
numbers in all windows of size K.

ALGORITHM:

Step 1 : Read the array of integers, A, with size N, and the window size, K.

Step 2 : Create an empty dictionary or set to store the distinct numbers in each window.

Step 3 : Initialize two variables: count = 0 (to keep track of the distinct numbers count) and window_start = 0 (to mark the
start of the current window).

Step 4 : Iterate from window_start to N - K + 1 (as the last possible window starts at index N - K).
Inside the loop, create a new empty dictionary or set for each window.
Iterate from window_start to window_start + K to process each element in the current window.
Add each element to the dictionary or set.
Increment the count by the length of the dictionary or set (representing the number of distinct elements in the window).
Increment window_start by 1 to move to the next window.

Step 5 : Print the count.

Step 6 : End the program

116
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

117
ROLL NO:221801031

EX NO : 59

DATE :

PROBLEM STATEMENT:

AIM:
To write an algorithm for A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase
and uppercase English letters.
A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.
For example, the sentence "This is a sentence can be shuffled as "sentence4 a3 is2 This 1" or "is2 sentence4
This1 a3".
Given a shuffled sentences containing no more than 9 words, reconstruct and return the original sentence.

ALGORITHM:

Step 1 : Read the shuffled sentence as input.

Step 2 : Split the shuffled sentence into individual words using the space character as the delimiter.

Step 3 : Create an empty dictionary or list to store the original position of each word.

Step 4 : Iterate over the words in the shuffled sentence.


Inside the loop, extract the original position of the word by removing the last character (which is the index) from the word.
Store the word in the dictionary or list using the original position as the key or index.

Step 5 : Sort the dictionary or list based on the keys or indices to arrange the words in the original order.

Step 6 : Join the words together using a space character as the separator to form the reconstructed original sentence.

Step 7 : Print or return the reconstructed original sentence.

Step 8 : End the program

118
ROLL NO:221801031

PROGRAM:

OUTPUT:

RESULT:

119
ROLL NO:221801031

EX NO : 60

DATE :

PROBLEM STATEMENT:

AIM:

To Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.

ALGORITHM:

Step 1 : Read the sentence as input.

Step 2 : Initialize two variables, uppercase_count and lowercase_count, to keep track of the counts of uppercase and lowercase
letters, respectively. Set both counts to 0.

Step 3 : Iterate over each character in the sentence.


Inside the loop, check if the current character is an uppercase letter by using the isupper() function.
If it is, increment the uppercase_count by 1.
Also, check if the current character is a lowercase letter by using the islower() function.
If it is, increment the lowercase_count by 1.

Step 4 : Print or display the values of uppercase_count and lowercase_count.

Step 5 : End the program.

120
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

121
ROLLNO:221801031

EX NO : 61
DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads values from the user until a blank line is entered. Display the total of all of the values
entered by the user (or 0 if the first value entered is a blank line). Complete this task using recursion. Your program may not use
any loops.
Hint: The body of your recursive function will need to read one value from the
user, and then determine whether or not to make a recursive call. Your function
does not need to take any arguments, but it will need to return a numeric result.

ALGORITHM:

Step 1: Define a recursive function called calculate_total without any arguments.


Step 2: Inside the calculate_total function:
- Read a value from the user as input.
- Check if the input value is a blank line. If it is, return 0.
- Convert the input value to a numeric type (e.g., int or float) and store it in a variable.
- Make a recursive call to calculate_total and add the returned value to the numeric value.
- Return the total.
Step 3: Call the calculate_total function and store the result in a variable.
Step 4: Print the total.

122
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

123
ROLLNO:221801031

EX NO : 62

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that implements Euclid's algorithm and uses it to determine the
greatest common divisor of two integers entered by the user. Test your program with some very large integers. The result will
be computed quickly, even for huge numbers consisting of hundreds of digits, because Euclid's algorithm is extremely efficient.

ALGORITHM:

Step 1: Define a recursive function called gcd that takes two integer arguments, a and b.
Step 2: Inside the gcd function:
- Check if b is equal to 0. If it is, return a as the GCD.
- Otherwise, calculate the remainder c when a is divided by b using the modulo operator (%).
- Make a recursive call to gcd with b as the first argument and c as the second argument.
- Return the result of the recursive call.
Step 3: Prompt the user to enter two integers, num1 and num2.
Step 4: Convert the user input to integers and store them in variables num1 and num2.
Step 5: Call the gcd function with num1 and num2 as arguments and store the result in a variable, result.
Step 6: Print the GCD of num1 and num2, which is stored in result.
Step 7: End the program

124
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

125
ROLLNO:221801031

EX NO : 63

DATE :

PROBLEM STATEMENT:

AIM:

To write a python program that reads a string from the user and uses your recursive function to determine whether or not it
is a palindrome. Then your program should
display an appropriate message for the user.

ALGORITHM:

Step 1: Define a recursive function called is_palindrome that takes a string argument, text.
Step 2: Inside the is_palindrome function:
- Check if the length of the string text is 0 or 1. If it is, return True since an empty string or a string with one character is a palindrome.
- Check if the first and last characters of the string text are equal. If they are not, return False.
- Make a recursive call to is_palindrome with the substring text[1:-1], which is the string formed by removing the first and last characters.
- Return the result of the recursive call.
Step 3: Prompt the user to enter a string and store it in a variable, input_string.
Step 4: Call the is_palindrome function with input_string as the argument and store the result in a variable, result.
Step 5: Check the value of result. If it is True, print a message indicating that the input string is a palindrome.
If it is False, print a message indicating that the input string is not a palindrome.
Step 6: End the program

126
ROLLNO:221801031

PROGRAM:

OUTPUT:

RESULT:

The required python program has been successfully implemented

127

You might also like