Python Record AI&DS 2023-------Clever (2)
Python Record AI&DS 2023-------Clever (2)
RAJALAKSHMI
ENGINEERING COLLEGE
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
Certifieð that this is the bonafide recorò of work done by the above student in the
External Examiner
Internal Examiner
INDEX
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:
1
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
3
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
5
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
7
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
9
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
11
ROLL NO: 221801031
PROGRAM:
OUTPUT:
RESULT:
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:
13
ROLL NO: 221801031
PROGRAM:
OUTPUT:
RESULT:
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:
15
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
17
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
19
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
21
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
23
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
25
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
27
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
29
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
31
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
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:
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:
36
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
38
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
40
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
42
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
44
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
46
ROLL NO: 221801031
PROGRAM:
OUTPUT:
RESULT:
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:
48
ROLL NO: 221801031
PROGRAM:
OUTPUT:
RESULT:
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:
50
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
52
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
53
ROLLNO:221801031
EX NO : 27
DATE :
PROBLEM STATEMENT:
AIM:
ALGORITHM:
54
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
56
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
58
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
59
ROLLNO:221801031
EX NO : 30
DATE :
PROBLEM STATEMENT:
AIM:
ALGORITHM:
60
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
62
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 2: Initialize two pointers, start and end, pointing to the first
and last elements of the array, respectively.
Step 4: Increment the start pointer and decrement the end pointer.
64
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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.
66
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
68
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
70
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
72
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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:
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 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:
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 2 : Initialize a set, alphabet_set, to store the unique lowercase letters encountered.
78
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 5 : Sort the list in ascending order using the sort method or the sorted function.
80
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 5 : Reverse the order of the list using the reverse method.
82
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 3 : Create a set from the list to remove duplicate words while preserving the order.
84
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 4 : Concatenate the negatives, zeros, and positives lists in that order.
86
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
88
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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.
90
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
92
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 5 : Create a tuple with the values ('Python', [8, 4, 6], (1, 2, 3)).
94
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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.
96
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 6 : Repeat the string in t3 ten times and create a new tuple repeated_tuple.
98
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 5 : Initialize a variable first_occurrence to None to store the location of the 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.
100
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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.
102
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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).
104
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
106
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 5 : Convert the unique_words set back into a list and sort it in alphabetical order, assigning it to a variable sorted_words.
Step 7 : Initialize a variable count to 0 to keep track of the words with a length greater than 3.
108
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 4 : Print the number of unique characters, which is the length of the unique_characters set.
110
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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".
112
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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.
114
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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.
116
ROLL NO:221801031
PROGRAM:
OUTPUT:
RESULT:
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 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 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.
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 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.
120
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
122
ROLLNO:221801031
PROGRAM:
OUTPUT:
RESULT:
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:
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:
127