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

Cse1005 - Sample - Questions - Module - 2

The document contains multiple coding problems that require writing Python programs for various tasks, such as extracting characters from strings, calculating averages while excluding limits, identifying the highest ratings, counting words, and reversing lists. Each problem includes input and output format descriptions along with test cases to validate the solutions. The problems are designed to enhance programming skills and understanding of basic algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views16 pages

Cse1005 - Sample - Questions - Module - 2

The document contains multiple coding problems that require writing Python programs for various tasks, such as extracting characters from strings, calculating averages while excluding limits, identifying the highest ratings, counting words, and reversing lists. Each problem includes input and output format descriptions along with test cases to validate the solutions. The problems are designed to enhance programming skills and understanding of basic algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

coding questions coding questions

1 Problem Statement: Imagine you are a teacher analyzing students' grades for a set of quizzes.
Write a Python program that extracts and outputs the characters at You want to calculate the average score for the students, but you decide to
odd indices (0-based index) of a given string. exclude the lowest and highest scores (like Quiz 1 and Quiz 5) because they
might not reflect the students' overall performance. You ask the user to input
Input Format Description: n scores, and the program calculates the average of the scores between two
The first line contains a string, which may consist of letters and other limits, excluding the scores at those limits.
characters.
Example Input: Problem:
Arijit Write a program that takes n numbers as input (representing student quiz
Output Format Description: scores), along with two limit numbers, and calculates the average of the
The output should be a string containing the characters at the odd scores that fall between the two limits, excluding the limits themselves. The
indices (0-based index) of the given string. limits are always limit1 and limit2, where limit1 is the lower bound and limit2
Example Output: is the upper bound.
rjt
Input Format:
Test Cases: First Line: An integer n, representing the number of elements in the list.
Test Case 1: Second Line: A space-separated list of n integers, representing the numbers
(e.g., student scores or values).
Input: Third Line: An integer limit1, representing the lower limit (this number and
Arijit numbers below it are excluded).
Output: Fourth Line: An integer limit2, representing the upper limit (this number and
rjt numbers above it are excluded).
Explanation: The characters at odd indices (0-based index) are "r",
"j", and "t". Test Cases:
Test Case 2: Test Case 1:
Input: Input:
priyanka 5
Output: 12345
ryna 2
Test Case 3: 4
Input: 3
HelloWorld Explanation: The numbers between limit1 = 2 and limit2 = 4 are 3, so the
Output: average is 3.
elWrd
Test Case 4: Test Case 2:
Input: Input:
Python 6
Output: yhn 10 15 20 25 30 35
Test Case 5: 15
Input: 30
Programming Output: 22
Output: rgamn
Test Case 6: Test Case 3:
Input: Input:
MachineLearning 5
Output: ahnLann 5 10 15 20 25
10
Solution: 20
input_string = input() Output: 15
odd_index_characters = ""
for i in range(1, len(input_string), 2): # Start from index 1 and step Test Case 4:
by 2 (odd indices) Input:
odd_index_characters += input_string[i] 7
print(odd_index_characters) 2 3 5 7 11 13 17
5
13
Output: 9

Test Case 5:
n=4
1234
1
4
Output: 2

Test Case 6:
Input:
6
8 9 10 11 12 13
9
12
Output: 10

Solution:
Solution:
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
limit1 = int(input())
limit2 = int(input())
total_sum = 0
count = 0
for i in arr:
if limit1 < i < limit2:
total_sum += i
count += 1
average = total_sum // count
print(average)
2 "Imagine you are a manager in a clothing store. The store sells Imagine you are working on a project for an e-commerce website. The
three different types of shirts, and you need to decide which shirt is website stores product ratings in a list for each product, where customers
the most expensive. The prices of the shirts vary, and your task is to can rate a product from 1 to 5. You need to develop a feature that identifies
compare these prices and determine which shirt is the highest- the highest rating given to a particular product.
priced so you can make decisions about sales or promotions.
For example, if a product has ratings 3 5 4 2 5 you need to identify the
You have three prices, and the program will help you determine highest rating (which is 5) so that you can highlight this on the product page.
which one is the largest, indicating the most expensive shirt.
Input Format Description:
Problem: The input consists of a list of integers.
Write a program that takes three prices as input and prints the Each integer is separated by a space.
highest one, helping you identify the most expensive shirt in the The list can have any five number of elements (including duplicates).
store.
Test Cases:
Test Cases: Test Case 1:3 5 4 2 1
Test Case 1: Output: 5
Scenario: The prices of three shirts are 4, 7, and 2 dollars. You need Explanation: The list contains multiple ratings, and the highest rating is 5.
to identify the most expensive shirt.
Test Case 2:-1 -5 -3 -9 -6
Input: #Output: -1
4, 7, 2 Test Case 3:42
Output: #Output: 42
7 Test Case 4:7 7 7 7 7
Test Case 2: #Output: 7
Input: Test Case 5:1 2 3 4 0
10, 20, 15 # Output: 4
Output: Test Case 6:-10 0 5 -20 7
20 # Output: 7
Test Case 3: Solution:
Input: n = int(input())
30, 25, 50 numbers = []
Output: for i in range(n):
50 num = int(input())
Test Case 4: numbers.append(num)
Input: largest = numbers[0]
5, 5, 5 for i in range(1, len(numbers)):
Output: if numbers[i] > largest:
5 largest = numbers[i]
Test Case 5: print(largest)
Input:
12, 8, 20
Output:
20
Test Case 6:
Input:
100, 25, 75
Output:
100

Solution:
a = int(input())
b = int(input())
c = int(input())
if a >= b and a >= c:
print(a)
elif b >= a and b >= c:
print(b)
else:
print(c)
3 Imagine you're working in a text analysis company that processes Problem Statement:
user reviews for a product. Your task is to determine how many Write a Python program to count the number of words in a string while
times a specific character appears in a given review text. This ignoring any extra spaces between words. The program should consider the
information is useful for sentiment analysis, to understand the words separated by space.
frequency of certain keywords or emotional indicators. For example,
if the character "!" appears frequently in a review, it might indicate
Input Format Description:
excitement. You need to create a program that takes a review The first line contains a string, which may contain words.
(string) and a character as input and returns how many times that Example Input:
character appears in the review. Kalyani Goverment Engineering College
Output Format Description:
Problem Statement: The output should be the total number of words in the string.
Write a Python program that takes a string and a character as input Example Output:
and outputs the number of times the character appears in the string. Number of words: 4

Input Format Description: Test Cases:


The first line contains a string, which is the review or the text. Test Case 1:
The second line contains a character, which you need to count in Input:
the string. Kalyani Goverment Engineering College
Example Input: Output:
Priyanka 4
a Explanation: The string contains 4 words: "Kalyani", "Goverment",
Output Format Description: "Engineering", and "College".
The output will be an integer representing the number of times the Test Case 2:
given character appears in the string. Input:
Example Output: Python Programming Language
2 Output:
3
Test Cases: Test Case 3:
Test Case 1: Input:
This is an example
Input: Output:
Priyanka 4
a Test Case 4:
Output: 2 Input:
Explanation: The character 'a' appears twice in "Priyanka". Cloud computing is awesome
Test Case 2: Output: Number of words: 4
Input: Test Case 5:
Hello World Input:
l Python is a great language
Output: 3 Output: Number of words: 5
Test Case 3: Test Case 6:
Input: Input:
test Case I love coding in Python
t Output: 5
Output: 2
Test Case 4: Solution:
Input: input_string = input()
python programming words = input_string.split()
p word_count = len(words)
Output: 2 print(word_count)
Test Case 5:
Input:
Data Science
e
Output: 2
Test Case 6:
Input:
OpenAI
O
Output: 1

Solution:
text = input()
char = input()
count = 0
for c in text:
if c == char:
count += 1
print(count)

Imagine you're working in a logistics company that tracks the number of


deliveries made by each truck. Management wants to know which trucks
have made an even number of deliveries so they can schedule those trucks
for maintenance or other tasks. You need to write a Python program that
takes the number of trucks and the corresponding deliveries made by each
truck, and prints only the trucks that made an even number of deliveries.

Problem Statement:
Imagine you are managing the order of tasks on your daily to-do list. Write a Python program that takes two lines of input:
You want to reverse the order of your tasks, such that the last task
becomes the first and the first task becomes the last. This helps you The first line contains the number of trucks (N) – though this number is just
reprioritize tasks for the day, especially when plans change. to indicate how many numbers will follow and is not directly used.
The second line contains N integers, representing the number of deliveries
Problem: made by each truck.
Write a program that takes a list of n integers (representing tasks or The program should print all even numbers from the list of deliveries.
items) and reverses the order of the list. The solution should not use
any built-in functions such as reverse(). Input Format Description:
The first line contains a single integer N (the number of trucks).
Input Format: The second line contains N space-separated integers, where each integer
First Line: An integer n, representing the number of elements in the represents the number of deliveries made by a truck.
list. Example Input:
Second Line: A space-separated list of n integers, representing the 5
tasks or values. 12345
Output Format Description:
Test Cases: The output will consist of space-separated even numbers from the list,
Test Case 1: printed in the order they appear.
Input: If no even numbers are found, no output is produced.
5 Example Output:
12345 24
Output:
54321 Test Cases:
Test Case 1:
Test Case 2:
Input: Input:
6 5
10 20 30 40 50 60 12345
Output: Output:
60 50 40 30 20 10 24
Explanation: The even numbers are 2 and 4.
Test Case 3: Test Case 2:
The second line contains N integers, representing the number of deliveries
Problem: made by each truck.
Write a program that takes a list of n integers (representing tasks or The program should print all even numbers from the list of deliveries.
items) and reverses the order of the list. The solution should not use
any built-in functions such as reverse(). Input Format Description:
The first line contains a single integer N (the number of trucks).
Input Format: The second line contains N space-separated integers, where each integer
First Line: An integer n, representing the number of elements in the represents the number of deliveries made by a truck.
list. Example Input:
Second Line: A space-separated list of n integers, representing the 5
tasks or values. 12345
Output Format Description:
Test Cases: The output will consist of space-separated even numbers from the list,
Test Case 1: printed in the order they appear.
Input: If no even numbers are found, no output is produced.
5 Example Output:
12345 24
Output:
54321 Test Cases:
Test Case 1:
Test Case 2:
Input: Input:
6 5
10 20 30 40 50 60 12345
Output: Output:
60 50 40 30 20 10 24
Explanation: The even numbers are 2 and 4.
Test Case 3: Test Case 2:
Input: 4
4 3279
7 14 21 28 Output:
Output: 2
28 21 14 7 Test Case 3:
Input:
Test Case 4: 6
Input: 2 4 6 8 10 12
3 Output: 2 4 6 8 10 12
987 Test Case 4:
Output: Input:
789 3
123
Test Case 5: Output: 2
Input: Test Case 5:
2 Input:
100 200 5
Output: 10 11 12 13 14
200 100 Output:
10 12 14
Test Case 6: Test Case 6:
Input: Input:
1 7
99 0123456
Output: Output:
99 0246

Solution: Solution:
n = int(input()) n = int(input())
arr = [] input_list = input().split()
for i in range(n): even_numbers = []
arr.append(int(input())) for num in input_list:
reversed_arr = [] num = int(num)
for i in range(n-1, -1, -1): if num % 2 == 0:
reversed_arr.append(arr[i]) even_numbers.append(num)
for i in reversed_arr: for even in even_numbers:
print(i, end=" ") print(even, end=" ")
5 "Problem Statement:
Write a Python program that takes a sentence as input and extracts
the first letter of each word to create an abbreviation or acronym.

Input Format Description:


The first line contains a sentence, which may consist of multiple
words.
Example Input:
Kalyani Govt. Eng. College
Output Format Description:
The output should be a string that contains the first letter of each
word in the sentence. Problem Statement:
Example Output: Write a Python program that takes multiple names as input and sorts them in
KGEC dictionary (lexical) order. After sorting, the program should output the names
in ascending order.
Test Cases:
Test Case 1: Input Format Description:
Input: The first line contains the number of names to be entered.
Kalyani Govt. Eng. College The following lines contain the names, one per line.
Output: KGEC Example Input:
Explanation: The first letter of each word is ""K"", ""G"", ""E"", and 3
""C"". Arijit
Test Case 2: Minaz
Input: Arnab
Computer Science and Engineering Output Format Description:
Output: CSaE The output should display the names in dictionary (lexical) order, each name
Test Case 3: on a new line.
Input: Example Output:
University of California Arijit
Output: UoC Arnab
Test Case 4: Minaz
Input:
National Institute of Technology Test Cases:
Output: NIoT Test Case 1:
Test Case 5:
Input: Input:
Indian Institute of Technology 3
Output: IIoT Arijit
Test Case 6: Minaz
Input: Arnab
Central Library Management System Output:
Output: CLMS Copy code
Arijit
Solution: Arnab
sentence = input() Minaz
words = sentence.split() Explanation: The names sorted in dictionary order are "Arijit", "Arnab", and
initials = """" "Minaz".
for word in words:
initials += word[0] Test Case 2:
print(initials) Input:
2
Alice
Bob
Output:
Alice
Bob

Test Case 3:
Input:
4
David
Carol
Alice
Bob
Output:
Alice
Bob
Carol
David

Test Case 4:
Input:
3
Zach
Yvonne
Xavier
Output:
Xavier
Yvonne
Zach

Test Case 5:
Input:
5
Emma
Olivia
Ava
Isabella
Sophia
Output:
Ava
Emma
Isabella
Olivia
Sophia

Test Case 6:
Input:
3
Jack
John
Jake
Output:
Copy code
Jack
Jake
John

Solution:
n = int(input())
names = []
for _ in range(n):
names.append(input())
names.sort()
for name in names:
print(name)

NO EASY-LEVEL
1 Write a program to calculate the sum of all even numbers up to a given number n.
Input Format: n: An integer representing the upper limit up to which even numbers will be summed (0 ≤ n ≤ 1000).
Sample Input: 10
Sample Output: 30

Solution:
Test Cases:
Input: 0 → Output: 0 n = int(input("Enter a number: "))
Input: 5 → Output: 6 total = 0
Input: 15 → Output: 56 for i in range(2, n + 1, 2):
Input: 2 → Output: 2 total += i
Input: 20 → Output: 110 print(total)
Input: 1 → Output: 0

Given a list of numbers with potential duplicates,


2 write a Python program to remove all duplicates and display the unique elements in the original order.
Input Format: numbers: A list of integers, entered as space-separated values.

Input Example: Enter numbers separated by spaces: 1 2 2 3 4 4 5


Output Example: Unique elements: [1, 2, 3, 4, 5]

Input: 1 1 1 1 1 → Output: [1]


Input: 1 2 3 4 5 → Output: [1, 2, 3, 4, 5] Solution:
numbers = list(map(int,input().split()))
Input: 5 4 3 2 1 → Output: [5, 4, 3, 2, 1] unique_numbers = []
Input: 1 2 2 3 3 4 4 5 5 → Output: [1, 2, 3, 4, 5] for num in numbers:
if num not in unique_numbers:
Input: 10 20 20 10 → Output: [10, 20] unique_numbers.append(num)
Input: 42 42 42 → Output: [42] print(unique_numbers)

Given two lists of integers, write a Python program to find and display the common elements between them,
3 without duplicates, in the order they appear in the first list.
Input Format:
The first line contains a space-separated integers representing list1.
list2: The second list of integers, entered as space-separated values.

Input Example:
Enter first list: 1 2 3 4 5 Solution:
Enter second list: 4 5 6 7 list1 = input("Enter first list: ").split()
list2 = input("Enter second list: ").split()
Output Example: common_elements = []
Common elements: [4, 5] for element in list1:
if element in list2 and element not in common_elements:
common_elements.append(element)
Test Cases: print("Common elements:", common_elements)
Input: 1 2 3 4, 3 4 5 6 → Output: [3, 4]
Input: 10 20 30, 30 20 10 → Output: [10, 20, 30]
Input: 1 2 3, 4 5 6 → Output: []
Input: 7 8 9, 8 9 7 → Output: [7, 8, 9]
Input: a b c d, d c b a → Output: [a, b, c, d]
Input: 5 6 7 8, 1 2 3 4 → Output: []

4 Write a Python program to input a tuple of numbers and calculate both the sum and the product of all elements.
Input Format:
The first line contains a string string (1 ≤ length of string ≤ 1000) in which vowels need to be counted

Input Example: Enter numbers separated by spaces: 1 2 3 4 Solution:


Output Example: Sum: 10, Product: 24
numbers = tuple(map(int, input("Enter numbers separated by spaces: ").split()))
total_sum = 0
Input: 1 2 3 4 → Output: Sum: 10, Product: 24 product = 1
Input: 5 → Output: Sum: 5, Product: 5 for num in numbers:
total_sum += num
Input: 0 1 2 3 → Output: Sum: 6, Product: 0 product *= num
Input: 2 3 5 → Output: Sum: 10, Product: 30 print("Sum:", total_sum)
print("Product:", product)
Input: 1 -1 1 -1 → Output: Sum: 0, Product: 1
Input: 7 8 9 → Output: Sum: 24, Product: 504

5 Write a Python program to count the number of vowels in a given string.


input format:

The first line contains a string string (1 ≤ length of string ≤ 1000) in which vowels need to be counted.

Input Example: Enter a string: hello world


Solution:
Output Example: Number of vowels: 3 string = input("Enter a string: ")
vowels = "aeiouAEIOU"
Test Cases: count = 0
for char in string:
Input: hello → Output: 2 if char in vowels:
Input: world → Output: 1 count += 1
print("Number of vowels:", count)
Input: aeiou → Output: 5
Input: bcdfg → Output: 0
Input: The quick brown fox → Output: 5
Input: PYTHON → Output: 0

NO MEDIUM - LEVEL

6 A user is entering text and wants to know if the sentence is a palindrome, ignoring spaces and punctuation.
Input Format:

The first line contains a string sentence, which may include spaces, punctuation, and mixed case letters. The length of the string will be between 1 and 1000.

(Case Insensitive)
Sample Input: "A man, a plan, a canal, Panama"
Solution:
Sample Output: "Palindrome"
sentence = input()
filtered_sentence = ""
reversed_sentence = ""

for char in sentence:


if 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '0' <= char <= '9':
if 'A' <= char <= 'Z':
filtered_sentence += chr(ord(char) + 32)
else:
filtered_sentence += char
for i in range(len(filtered_sentence) - 1, -1, -1):
reversed_sentence += filtered_sentence[i]
if filtered_sentence == reversed_sentence:
print("Palindrome")
Solution:
sentence = input()
filtered_sentence = ""
Test Cases: reversed_sentence = ""

Input: "Madam" → Output: "Palindrome" for char in sentence:


Input: "Hello World" → Output: "Not a Palindrome" if 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '0' <= char <= '9':
if 'A' <= char <= 'Z':
Input: "Was it a car or a cat I saw" → Output: "Palindrome" filtered_sentence += chr(ord(char) + 32)
Input: "No lemon, no melon" → Output: "Palindrome" else:
Input: "Python is fun" → Output: "Not a Palindrome" filtered_sentence += char
for i in range(len(filtered_sentence) - 1, -1, -1):
Input: "Able was I, I saw Elba" → Output: "Palindrome" reversed_sentence += filtered_sentence[i]
if filtered_sentence == reversed_sentence:
print("Palindrome")
else:
print("Not a Palindrome")

7 Create a program to replace vowels in a sentence with underscores to make a guessing game for children.
Input Format:

The first line contains a string sentence (1 ≤ length of string ≤ 1000) in which vowels need to be replaced by underscores.

Sample Input: "Hello World"


Solution:
Sample Output: "H_ll_ W_rld" sentence = "Hello World"
vowels = "aeiouAEIOU"
result = ""
Test Cases:
Input: "python" → Output: "pyth_n" for char in sentence:
Input: "AEIOU" → Output: "_____" if char in vowels:
result += "_"
Input: "Python is fun" → Output: "Pyth_n _s f_n" else:
Input: "Guessing game" → Output: "G_ss_ng g_m_" result += char
Input: "Happy Birthday" → Output: "H_ppy B_rthd_y" print(result)
Input: "" → Output: "" # Output: "H_ll_ W_rld"

8 Given a list of words from a document, find and count all duplicate words.
Input Format:

The first line contains a space-separated string of words words (1 ≤ length of list ≤ 1000). Some words may be duplicated.

Sample Input: ["apple", "banana", "apple", "orange", "banana", "apple"]


Solution:
Sample Output: {"apple": 3, "banana": 2} words = ["apple", "banana", "apple", "orange", "banana", "apple"]
word_count = {}
duplicate_words = {}
Test Cases:
Input: ["a", "b", "a", "c", "b"] → Output: {"a": 2, "b": 2} for word in words:
if word in word_count:
Input: ["hello", "world"] → Output: {} word_count[word] += 1
Input: ["test", "test", "test"] → Output: {"test": 3} else:
Input: ["x", "y", "z", "x", "y", "z"] → Output: {"x": 2, "y": 2, "z": 2} word_count[word] = 1

Input: ["unique"] → Output: {} for word in word_count:


Input: ["repeat", "repeat", "repeat", "different"] → Output: {"repeat": 3} if word_count[word] > 1:
duplicate_words[word] = word_count[word]

print(duplicate_words) # Output: {"apple": 3, "banana": 2}

A library stores information about available and checked-out books.


9 Given two lists, one with all books and one with checked-out books, write a Python program to find and display the books currently available.
Input Format:

The first line contains a space-separated string of all_books, representing the list of all books in the library.
The second line contains a space-separated string of checked_out_books, representing the list of books currently checked out.

Input/Output:
Enter all books: Book1 Book2 Book3 Book4
Enter checked-out books: Book2 Book4
Available books: ['Book1', 'Book3'] Solution:

all_books = input("Enter all books: ").split()


checked_out_books = input("Enter checked-out books: ").split()
available_books = []
Test Cases:
for book in all_books:
Input: Book1 Book2 Book3 Book4, Book2 Book4 → Output: ['Book1', 'Book3'] if book not in checked_out_books:
Input: A B C D, B → Output: ['A', 'C', 'D'] available_books.append(book)
Input: Python Java C++, Java → Output: ['Python', 'C++']
Input: History Math Science, `` (none checked out) → Output: ['History', 'Math', 'Science'] print("Available books:", available_books)
Input: Novel, Novel → Output: []
Input: BookA BookB BookC, BookD → Output: ['BookA', 'BookB', 'BookC']

A teacher needs to assign students to seats, filling available seats from the front.
10 Given two lists — a list of all seats and a list of occupied seats — write a Python program to display the list of available seats in order.
Input Format:

The first line contains a space-separated string of all_seats, representing the list of all seats in the classroom.
The second line contains a space-separated string of occupied_seats, representing the list of seats that are currently occupied.

Input/Output:
Enter all seats separated by spaces: A1 A2 A3 A4
Enter occupied seats separated by spaces: A2 A4 Solution:
all_seats = input("Enter all seats separated by spaces: ").split()
Available seats: ['A1', 'A3'] occupied_seats = input("Enter occupied seats separated by spaces: ").split()
available_seats = []
Test Cases:
for seat in all_seats:
if seat not in occupied_seats:
Input: A1 A2 A3 A4, A2 A4 → Output: ['A1', 'A3'] available_seats.append(seat)
Input: B1 B2 B3, B1 → Output: ['B2', 'B3'] print("Available seats:", available_seats)
Input: C1 C2 C3, C3 → Output: ['C1', 'C2']
Input: D1 D2, D1 D2 → Output: []
Input: E1 E2 E3 E4, `` (none occupied) → Output: ['E1', 'E2', 'E3', 'E4']
Input: F1, F1 → Output: []

Coding Questions Coding Questions


1. Find Maximum Element in a List

Input Format:
The input will be a list of numbers (integers or floating-point numbers).
You can assume that the list will contain at least one element.
Output Format:
The program should output the maximum element in the list. 5. Given a list of integers, find the second largest element.

my_list = [4, 1, 7, 3, 9] my_list = [10, 20, 4, 45, 99]


maximum = max(my_list) sorted_list = sorted(set(my_list)) # Remove duplicates and sort
print(maximum) # Output: 9 second_largest = sorted_list[-2] if len(sorted_list) >= 2 else None
print(second_largest) # Output: 45
Test Cases: Test Cases:
Test 1: my_list = [1, 2, 3] → Output: 3
Test 2: my_list = [5, 4, 3] → Output: 5 Test 1: my_list = [1, 3, 4, 5] → Output: 4
Test 3: my_list = [-1, -2, -3] → Output: -1 Test 2: my_list = [10, 10, 10] → Output: None (no second largest)
Test 4: my_list = [10, 10, 10] → Output: 10 Test 3: my_list = [5, 5, 5, 8, 8, 8, 1] → Output: 5
Test 5: my_list = [0, 100, -50] → Output: 100 Test 4: my_list = [7] → Output: None
1 Test 5: my_list = [2, 9, 2, 1] → Output: 2
6. Given a list, check if it is a palindrome (reads the same forwards and backwards).
2. Given a list, reverse the order of its elements.
Input Format:
Input Format: The input will consist of a list of elements, which could be integers, strings, or any other type.
The input will be a list of elements, which could be integers, strings, or mixed types.
The list will contain at least one element.
The list will contain at least one element. Output Format:
Output Format: The program should output True if the list is a palindrome.
The program should output the reversed list. Otherwise, the program should output False.

my_list = [1, 2, 3, 4, 5] my_list = [1, 2, 3, 2, 1]


reversed_list = my_list[::-1] is_palindrome = my_list == my_list[::-1]
print(reversed_list) # Output: [5, 4, 3, 2, 1] print(is_palindrome) # Output: True
Test Cases:
Test Cases:
Test 1: my_list = [1, 2, 3] → Output: [3, 2, 1] Test 1: my_list = [1, 2, 3, 2, 1] → Output: True
Test 2: my_list = [5, 10, 15] → Output: [15, 10, 5] Test 2: my_list = [1, 2, 3] → Output: False
Test 3: my_list = [0, -1, -2] → Output: [-2, -1, 0] Test 3: my_list = [10, 20, 20, 10] → Output: True
Test 4: my_list = [100] → Output: [100] Test 4: my_list = [5, 5, 5] → Output: True
2 Test 5: my_list = [] → Output: [] Test 5: my_list = [] → Output: True

3. Given a list, find the sum of all elements in the list. 7. Given a list of integers, find all the elements that appear more than once.

Input Format: Input Format:


The input will be a list of numbers (integers or floating-point numbers). The input will be a list of integers.
The list will contain at least one element. The list will contain at least one integer.
Output Format: Output Format:
The program should output the sum of all elements in the list. The program should output a list of integers that appear more than once in the input list. The output list should not contain duplicates.

my_list = [1, 2, 3, 4, 5] my_list = [1, 2, 2, 3, 3, 3]


total = sum(my_list) duplicates = list(set([x for x in my_list if my_list.count(x) > 1]))
print(total) # Output: 15 print(duplicates) # Output: [2, 3]
Test Cases:
Test Cases:
Test 1: my_list = [1, 2, 3, 4, 4, 5] → Output: [4]
Test 1: my_list = [1, 2, 3] → Output: 6 Test 2: my_list = [10, 20, 30, 20, 30, 40] → Output: [20, 30]
Test 2: my_list = [5, 10, 15] → Output: 30 Test 3: my_list = [1, 1, 1, 1] → Output: [1]
Test 3: my_list = [0, -1, -2] → Output: -3 Test 4: my_list = [5, 6, 7, 8] → Output: []
Test 4: my_list = [] → Output: 0 Test 5: my_list = [9, 9, 9, 9, 9, 9] → Output: [9]
3 Test 5: my_list = [100, 200] → Output: 300
4. Given a list, find the maximum element in the list.

Input Format: 9.Replace all spaces in a string with hyphens (-).9.Replace all spaces in a string with hyphens (-).
The input will be a list of integers.
The list will contain at least one integer. Input Format:
Output Format: The input will be a string that may contain spaces.
The program should output the maximum integer in the list. Output Format:
The program should output a string where all spaces are replaced by hyphens (-).
my_list = [4, 1, 7, 3, 9]
maximum = max(my_list) my_string = "hello world"
print(maximum) # Output: 9 replaced_string = my_string.replace(" ", "-")
print(replaced_string) # Output: hello-world
Test Cases: Test Cases:

Test 1: my_list = [1, 2, 3] → Output: 3 Test 1: my_string = "this is python" → Output: this-is-python
Test 2: my_list = [5, 4, 3] → Output: 5 Test 2: my_string = "Open AI" → Output: Open-AI
Test 3: my_list = [-1, -2, -3] → Output: -1 Test 3: my_string = "no_spaces" → Output: no_spaces
Test 4: my_list = [10, 10, 10] → Output: 10 Test 4: my_string = "hello " → Output: hello-
Test 5: my_list = [0, 100, -50] → Output: 100 Test 5: my_string = "" → Output: ""
4
8. Given a string, count how many vowels (a, e, i, o, u) it contains.

Input Format:
The input will be a string that may contain both uppercase and lowercase
letters.
The string can also contain spaces, punctuation, or other non-alphabet
characters.
Output Format:
The program should output a single integer representing the number of 10. Given a string, check if it is a palindrome (reads the same forwards and backwards).
vowels in the input string.
Input Format:
my_string = "Hello World" The input will be a single string that may contain letters, digits, spaces, and punctuation marks.
vowels = "aeiouAEIOU" The program should ignore spaces, punctuation, and capitalization when checking for palindromes.
vowel_count = 0 Output Format:
The program should output True if the string is a palindrome, otherwise False.
for char in my_string:
if char in vowels: my_string = "madam"
vowel_count += 1 is_palindrome = my_string == my_string[::-1]
print(is_palindrome) # Output: True
print(vowel_count) # Output: 3
Test Cases:
Test Cases:
Test 1: my_string = "level" → Output: True
Test 1: my_string = "apple" → Output: 2 Test 2: my_string = "world" → Output: False
Test 2: my_string = "PYTHON" → Output: 1 Test 3: my_string = "racecar" → Output: True
Test 3: my_string = "OpenAI" → Output: 4 Test 4: my_string = "hello" → Output: False
Test 4: my_string = "" → Output: 0 Test 5: my_string = "a" → Output: True
Test 5: my_string = "AEIOU" → Output: 5
5
Write a python program to find the Longest Palindromic Substring

nput Format:
The input will be a string that can contain both uppercase and lowercase letters.
Write a program to check if a String Contains All Vowels Output Format:
The program should output the longest palindromic substring.
Input Format:
The input will be a string that may contain both uppercase and lowercase # Input
characters. s = input("Enter a string: ")
Output Format:
The program should output True if the string contains all the vowels (a, e, i, # Processing
o, u), otherwise False. n = len(s)
longest_palindrome = ""
# Input for i in range(n):
s = input("Enter a string: ").lower() for j in range(i, n):
substring = s[i:j+1]
# Processing if substring == substring[::-1] and len(substring) > len(longest_palindrome):
vowels = set("aeiou") longest_palindrome = substring
contains_all_vowels = vowels.issubset(set(s))
# Output
# Output print("Longest palindromic substring:", longest_palindrome)
print("Contains all vowels:", contains_all_vowels)
# Test cases
# Test cases # Input: "babad" → Output: "bab" or "aba"
# Input: "education" → Output: True # Input: "cbbd" → Output: "bb"
# Input: "hello" → Output: False # Input: "forgeeksskeegfor" → Output: "geeksskeeg"
# Input: "sequoia" → Output: True # Input: "racecar" → Output: "racecar"
# Input: "rhythm" → Output: False # Input: "a" → Output: "a"
# Input: "facetious" → Output: True

Write a program that finds all pairs of numbers in a list that sum to a
given target.

Input Format:
The input will consist of two lines: Write a program to find the First Non-Repeating Character in python
A list of integers, representing the numbers in the list.
An integer target, representing the sum you are looking for. Input Format:
Output Format: The input will be a string containing alphanumeric characters (letters and digits).
The program should output all unique pairs of numbers that add up to the Output Format:
target sum. Each pair should be printed on a new line. The program should output the first non-repeating character in the string, or -1 if there is no non-repeating character.

# Input # Input
lst = list(map(int, input("Enter numbers separated by spaces: ").split())) s = input("Enter a string: ")
target = int(input("Enter target sum: "))
# Processing
# Processing for char in s:
pairs = [] if s.count(char) == 1:
for i in range(len(lst)): first_non_repeating = char
for j in range(i+1, len(lst)): break
if lst[i] + lst[j] == target: else:
pairs.append((lst[i], lst[j])) first_non_repeating = None

# Output # Output
print("Pairs that sum to", target, ":", pairs) print("First non-repeating character:", first_non_repeating)

# Test cases: # Test cases


# Input: 1 2 3 4 5, 5 → Output: [(1, 4), (2, 3)] # Input: "swiss" → Output: "w"
# Input: 10 20 30, 30 → Output: [(10, 20)] # Input: "hello" → Output: "h"
# Input: 5 5 5 5, 10 → Output: [(5, 5), (5, 5), (5, 5)] # Input: "aabbcc" → Output: None
# Input: 1 2 3, 6 → Output: [] # Input: "programming" → Output: "p"
# Input: 4 4 2 2, 6 → Output: [(4, 2), (4, 2)] # Input: "abacabad" → Output: "c"
Write a program to find the longest contiguous sublist where all elements are equal.

Input Format:
The input will consist of a list of elements (can be integers, strings, etc.).
Output Format:
The program should output the length of the longest contiguous sublist where all elements are equal, followed by the sublist itself.

# Input
lst = list(map(int, input("Enter numbers separated by spaces: ").split()))

# Processing
Write a program to Check if a String is an Anagram max_len = 1
current_len = 1
Input Format: longest_value = lst[0]
The input will consist of two strings. for i in range(1, len(lst)):
Output Format: if lst[i] == lst[i-1]:
The program should output True if the strings are anagrams of each other, current_len += 1
otherwise False. else:
if current_len > max_len:
# Input max_len = current_len
str1 = input("Enter the first string: ").lower().replace(" ", "") longest_value = lst[i-1]
str2 = input("Enter the second string: ").lower().replace(" ", "") current_len = 1
if current_len > max_len:
# Processing longest_value = lst[-1]
is_anagram = sorted(str1) == sorted(str2)
# Output
# Output print("Longest sublist element:", longest_value, "Length:", max_len)
print("Are anagrams:", is_anagram)
# Test cases:
# Test cases # Input: 1 1 2 2 2 3 → Output: 2, Length: 3
# Input: "listen", "silent" → Output: True # Input: 5 5 5 5 6 7 → Output: 5, Length: 4
# Input: "hello", "world" → Output: False # Input: 1 1 1 1 1 → Output: 1, Length: 5
# Input: "dormitory", "dirty room" → Output: True # Input: 9 9 9 8 8 → Output: 9, Length: 3
# Input: "conversation", "voices rant on" → Output: True # Input: 7 8 9 9 → Output: 9, Length: 2
# Input: "python", "typhon" → Output: True
Write a program that finds all pairs of numbers in a list that sum to a given target.

Input Format:
Create Acronym from Sentence. The input will consist of:
A list of integers (can include positive and negative numbers).
Input Format: A target sum (integer).
The input will be a single sentence (a string), consisting of words separated Output Format:
by spaces. The program should output all pairs of numbers (in the form of tuples) that sum to the target sum.
Output Format:
The program should output a single string, which is the acronym created # Input
from the sentence. lst = list(map(int, input("Enter numbers separated by spaces: ").split()))
target = int(input("Enter target sum: "))
# Input
sentence = input("Enter a sentence: ") # Processing
pairs = []
# Processing for i in range(len(lst)):
acronym = "" for j in range(i+1, len(lst)):
for word in sentence.split(): if lst[i] + lst[j] == target:
acronym += word[0].upper() pairs.append((lst[i], lst[j]))

# Output # Output
print("Acronym:", acronym) print("Pairs that sum to", target, ":", pairs)

# Test cases # Test cases:


# Input: "As Soon As Possible" → Output: "ASAP" # Input: 1 2 3 4 5, 5 → Output: [(1, 4), (2, 3)]
# Input: "National Aeronautics and Space Administration" → Output: "NASA" # Input: 10 20 30, 30 → Output: [(10, 20)]
# Input: "Machine Learning" → Output: "ML" # Input: 5 5 5 5, 10 → Output: [(5, 5), (5, 5), (5, 5)]
# Input: "Artificial Intelligence" → Output: "AI" # Input: 1 2 3, 6 → Output: []
# Input: "World Health Organization" → Output: "WHO" # Input: 4 4 2 2, 6 → Output: [(4, 2), (4, 2)]

1 Palindrome Checker Count Vowels and Consonants


A palindrome is a string that reads the same forwards and backwards. Write a program that checks if a given string is a palindrome.

Input Format Write a program to count the number of vowels and consonants in a given string.
A single line containing a string s consisting of alphanumeric characters only.
Output Format Input Format
Print "YES" if the string is a palindrome, otherwise print "NO". A single line containing a string s (consisting of alphabetic characters only).
Constraints Output Format
1≤length of 𝑠≤10^5 Print two space-separated integers: the number of vowels and the number of consonants in the string.
1≤length of s≤10^5 Constraints
1≤length of 𝑠≤10^5
The string contains only lowercase letters (a-z) and/or digits (0-9).
1≤length of s≤10^5
Sample Input 0 The string s contains only lowercase letters (a-z).
madam
Sample Output 0 Sample Input 0
YES hello
Sample Input 1 Sample Output 0
hello 23
Sample Output 1
NO code:
s = input().strip()
code: vowels = 0
s = input().strip() consonants = 0
if s == s[::-1]: vowel_set = {'a', 'e', 'i', 'o', 'u'}
print("YES") for char in s:
else: if char in vowel_set:
print("NO") vowels += 1
else:
Testcase 1: consonants += 1
Input: print(vowels, consonants)
abcdefgh
Output: Test Case 1
NO Input:
abcde
Output:
Testcase 2: 23
Input:
aabbcbbaa Test Case 2
Output: Input:
YES aeiou
Output:
50
Testcase 3:
Input: Test Case 3
a...a (100,000 "a" characters) Input:
Output: bcdfghjklmnpqrstvwxyz
YES Output:
0 21

Testcase 4: Test Case 4


Input: Input:
abccbx programming
Output: Output:
NO 38

2 List Comprehensions List Rotation


Rotate a list to the right by k steps.
Input Format
The first line contains an integer n, the number of elements in the list.
The second line contains n space-separated integers.
The third line contains an integer k, the number of steps to rotate.

Output Format
Print the rotated list as a space-separated string.
Constraints
0≤k≤n

Sample Input
5
12345
2
Sample Output
45123

code:

n = int(input())
arr = list(map(int, input().split()))
You are given an integer N. Use list comprehension to create a list that kcontains
= int(input())
the squares of all numbers from 1 to N (inclusive).
Write a Python program that generates the list of squares using list comprehension.
k=k%n
Input: rotated_list = arr[-k:] + arr[:-k]
A single integer N (1 ≤ N ≤ 1000) print(" ".join(map(str, rotated_list)))
Output:
A list containing the squares of numbers from 1 to N, inclusive.

Input:
Test Case 1:
Input:
5 7
Output: 10 20 30 40 50 60 70
[1, 4, 9, 16, 25] 3
Output:
50 60 70 10 20 30 40
code:
N = int(input()) Test Case 2:
squares = [x**2 for x in range(1, N+1)] Input:
print(squares)
5
Test Case 1:
12345
Input: 0
3 Output:
Output: 12345
[1, 4, 9]
Test Case 3:
Test Case 2: Input:
Input: 6
5 123456
Output: 6
[1, 4, 9, 16, 25]
Output:
Test Case 3:
123456
Input:
1 Test Case 4:
Output: Input:
[1] 4
10 20 30 40
1
Test Case 4: Output:
Input: 40 10 20 30
10
Output:
Test Case 5:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Input:
Test Case 5: 3
Input: 5 10 15
8 4
Output: Output:
[1, 4, 9, 16, 25, 36, 49, 64] 10 15 5
3 Sum of Even and Odd Elements Find the missing number
Given a list of integers from 1 to n, where some numbers may be missing, write a program to find and return all the missing numbers in sorted order.

Input Format
The first line contains an integer, n, which represents the maximum number in the full sequence (from1 to n).
The second line contains space-separated integers, representing the list of numbers with some missing elements.
Constraints
Given a list of integers, calculate the sum of even numbers and the sum1≤𝑛≤10^5
of odd numbers separately.
Input Format 1≤n≤10^5
The first line contains an integer n, the number of elements in the list.
The second line contains n space-separated integers. Each integer in the list is unique and within the range from 1 to n.
Output Format
Output Format Print the missing numbers in ascending order, separated by spaces.
Print two space-separated integers: the sum of even numbers and the sum If noofnumbers
odd numbers.
are missing, print No missing numbers.
Sample Input
Sample Input 6
5 1246
12345 Sample Output
Sample Output 35
69
code:
n = int(input())
code: numbers = list(map(int, input().split()))
n = int(input()) missing_numbers = []
arr = list(map(int, input().split()))
even_sum = 0 for i in range(1, n + 1):
odd_sum = 0 if i not in numbers:
for num in arr: missing_numbers.append(i)
if num % 2 == 0:
even_sum += num if missing_numbers:
else: print(" ".join(map(str, missing_numbers)))
odd_sum += num else:
print(even_sum, odd_sum) print("No missing numbers")

Test Case 1 Test Case 1:


Input: Input:
3 5
123 54321
Output: Output:
24 No missing numbers

Test Case 2 Test Case 2:


Input: Input:
4 10
10 15 20 25 124579
Output: Output:
30 40 3 6 8 10

Test Case 3 Test Case 3:


Input: Input:
6 3
-1 -2 -3 -4 -5 -6 13
Output: Output:
-12 -9 2

Test Case 4 Test Case 4:


Input: Input:
5 7
2 4 6 8 10 7654321
Output: Output:
30 0 No missing numbers

Test Case 5 Test Case 5:


Input: Input:
5 4
13579 123
Output: Output:
0 25 4

4 Multiply All Elements in a List Find the Second largest element


Given a list of numbers, your task is to find the second largest unique number in the list. If the largest number appears more than once, ignore the duplicates and return the second largest unique number.

Input Format:
You are given a list of integers. Your task is to calculate the product of all elements in the list and print the result.
A single line containing space-separated integers.
Constraints:
Input Format
The list will contain at least two numbers.
The first line contains an integer, n, the number of elements in the list.
Output Format:
The second line contains n space-separated integers, representing the elements of the list.
Return the second largest unique number.
Output Format
Print the product of all elements in the list.
Sample Input:
Constraints
10 20 4 45 99 99
1≤𝑛≤10^3 Sample Output:
−10^3≤element≤10^3 45
Sample Input 1 code:
4 numbers = list(map(int, input().split()))
1234 numbers.sort(reverse=True)
Sample Output 1 for i in range(1, len(numbers)):
24 if numbers[i] != numbers[0]:
print(numbers[i])
code: break
n = int(input())
numbers = list(map(int, input().split())) Test Case 1:
product = 1 Input:
for num in numbers: 15 10 15 20 25 25 30
product *= num Output:
print(product) 25
Testcase1: Test Case 2:
input : Input:
4 5 5 10 10 5
5555 Output:
Output: 5
625
Testcase 2: Test Case 3:
Input Input:
4 8273743
0123 Output:
Output 4
0

Testcase 3: Test Case 4:


Input Input:
4 1312
-1 2 -3 4 Output:
Output
24 2

Testcase 4: Test Case 5:


Input Input:
1 99 55 33 99 55
10
Output
Output:
10 55

5 Count Occurrences of Each Element Weather Analysis


You are given a list of temperatures recorded over a week (7 days). Each temperature is for one day. Your task is to:

Find the highest temperature recorded during the week.


Find the lowest temperature recorded during the week.
Given a list of integers, count the occurrences of each element and displayCalculate
them. the average temperature of the week, rounded to two decimal places.
Determine the day number with the highest temperature (Day 1 for the first day, Day 2 for the second, and so on).
Input Format
The first line contains an integer n, the number of elements in the list. Input Format:
The second line contains n space-separated integers. A single line containing 7 space-separated integers representing the temperatures recorded each day.
Output Format Output Format:
Print each unique element followed by its count, in the order of their firstFirst
appearance.
line: Print the highest temperature.
Sample Input Second line: Print the lowest temperature.
7 Third line: Print the average temperature (rounded to two decimal places).
1223334 Fourth line: Print the day number with the highest temperature in this format: Day X.
Sample Output
11 Constraints
22 There are exactly 7 temperatures (one for each day of the week).
33 Each temperature is an integer.
41
Sample Input
code: 25 28 31 29 30 32 27
n = int(input()) Sample Output
numbers = list(map(int, input().split())) 32
unique_elements = [] 25
occurrences = {} 28.86
for num in numbers: Day 6
if num not in occurrences:
occurrences[num] = 1 code:
unique_elements.append(num) # Keep track of the first appearance order
else: temperatures = list(map(int, input().strip().split()))
occurrences[num] += 1 highest_temp = max(temperatures)
for num in unique_elements: lowest_temp = min(temperatures)
print(num, occurrences[num]) average_temp = sum(temperatures) / len(temperatures)
highest_temp_day = temperatures.index(highest_temp) + 1

Test Case 1: print(highest_temp)


Input: print(lowest_temp)
5 print(f"{average_temp:.2f}")
55555 print(f"Day {highest_temp_day}")
Output:
55 Test Case 1
Input:
Test Case 2: 25 28 31 29 30 32 27
Input: Output:
4 32
10 20 20 30 25
Output: 28.86
10 1 Day 6
20 2
30 1 Test Case 2
Input:
Test Case 3: 20 20 20 20 20 20 20
Input: Output:
6 20
111111 20
Output: 20.00
16 Day 1

Test Case 4: Test Case 3


Input: Input:
8 15 30 25 28 34 29 20
45467888 Expected Output:
Output: 34
15
42 25.86
51 Day 5
61
71
83 Test Case 4
Input:
Test Case 5: 10 50 10 50 10 50 10
Input: Output:
10 50
9876543210 10
Output: 27.14
91 Day 2
81
71 Test Case 5
61 Input:
51 32 28 33 27 35 31 29
41 Output:
31 35
21 27
11 30.71
01 Day 5
You are a project manager at a local library, and you are organizing a new
digital catalog for the books in your collection. The library staff has provided
you with a list of book titles, but some titles are repeated due to data entry
errors. To ensure a clean and organized catalog, you need to create a
program that removes duplicate book titles while keeping the original order
intact.
Your task is to write a Python program that processes the list of book titles.
This program should identify and remove any duplicate titles, ensuring that
each title appears only once in the final output.

Input Format:
The program will first prompt the user to input a list of book titles.
The user should input the book titles as a single string, where each title is You are developing a language-learning app aimed at helping users improve their reading and writing skills. As part of the app, you want to include a fun feature that checks whether a given
separated by a comma. word or phrase is a palindrome. A palindrome is a string that reads the same forwards and backwards, ignoring spaces, punctuation, and capitalization.
The program will process this list, remove duplicate titles, and preserve the Your task is to write a Python program that prompts the user to enter a word or phrase, then checks whether it is a palindrome. This feature will enhance user engagement and provide
original order. educational value by helping users understand the concept of palindromes.
sample input: Physics,chemistry,signals,physics
Input Format:
Output Format: The program will prompt the user to input a word or phrase.
The program should print a list of book titles, with each title appearing only The user can enter a string that may include spaces, punctuation, and different letter case (upper or lower).
once, and the order should be preserved as in the original input. sample input1: "malayalam, malayalam"
sample output: ["Physics", "chemistry", "signals"] sample input2: "john"

Output Format:
Code: The program should print a message "palindrome" if it is palindrome and "not a palindrome" otherwise.
List = list(map(str, input("enter the book titles seperated by comma : ").split sample output1: palindrome
(","))) sample output2: not a palindrome
L=[]
for book in List: Code:
if book not in L: user_input = input("Please enter a word or phrase: ")
L.append(book) words = "".join(char.lower() for char in user_input if char.isalnum())
print(L) if words == words[::-1]:
print("palindrome.")
Test Cases: else:
Test 1: input: M1,M2,M1,M3,M2 --> output: ["M1","M2","M3"] print("not a palindrome.")
Test 2: input: Physics,chemistry,signals,physics --> output: ["Physics","
chemistry","signals"] Test Cases:
Test 3: input: a,b,c,a,c --> output: ['a','b','c'] Test 1: input: a man, a plan, a canal, Panama --> output: palindrome
Test 4: input: 1,a,2,b,1,2 --> output: ["1","a","2","b"] Test 2: input: race car --> output: palindrome
Test 5: input: c,a,c,t,a --> output: ['c','a','t'] Test 3: input: the holy book --> output: not a palindrome
Test 6: Input: apple,banana,apple,orange,banana,grape --> Output: Test 4: input: the first book --> output: not a palindrome
["apple","banana","orange","grape"] Test 5: Input: No lemon, no melon --> Output: palindrome
Test 7: Input: 5, 3, 5, 7, 9, 3, 7, 10 --> Output: ["5","3","7","9","10"] Test 6: Input: Hello World --> Output: not a palindrome
1
You are working as a software developer for an educational app aimed at helping children learn to read. One of the features of the app is a fun game that encourages users to identify vowels in
words. To make the game more engaging, you decide to create a program that takes a user's input string and replaces all the vowels (a, e, i, o, u) with the symbol "_". This will allow the children
to guess the missing vowels as they practice their reading skills.
Your task is to write a Python program that performs this vowel replacement.

Input Format:
The program will prompt the user to input a string.
The string can contain letters (both lowercase and uppercase) and other characters (such as punctuation or spaces).
Imagine you're working for an e-commerce platform and have been asked to sample input: cake
create a feature that helps users keep track of the items in their shopping
cart. Each item added to the cart is stored in a list, and you need to calculate Output Format:
how many items the user has selected in their cart. The program will print the modified string where all vowels (a, e, i, o, u) have been replaced with the symbol "_".
The goal is to write a Python program that will count the number of items in sample output: c_k_
the shopping cart list and display the result. This will allow the user to see
how many products they have chosen before proceeding to checkout. Code:
word = input("enter the string: ")
input format: vowels = "AEIOUaeiou"
Take a list of items seperated by comma representing products in the w = ""
shopping cart. for letter in word:
Count the number of items in the cart. if letter in vowels:
sample input: laptophe,adphones,mouse,keyboard w=w+"_"
else:
output format: w=w+letter
Print the total number of items. print(w)
sample output: 4
Test Cases:
test cases: Test 1: input: hello world --> output: h_ll_ w_rld
input: laptop,headphones,mouse --> output: 3 Test 2: input: python --> output: pyth_n
input: --> output: Test 3: input: Alphabets --> output: _lph_b_ts
input: apple,banana,apple,orange --> output: 4 Test 4: input: TRAINER --> output: TR_ _N_R
input: t-shirt --> output: 1 Test 5: input: presidency --> output: pr_s_d_ncy
input: laptop,headphones --> output: 2 Test 6: Input: umbrella --> Output: _mbr_ll_
2 input: phone case,phone case,phone case --> output: 3 Test 7: Input: Programming --> Output: Pr_gr_mm_ng
You are a data analyst at a tech company, and you have been tasked with
analyzing the performance of different products based on their sales figures.
The sales data is provided to you in the form of a list of numbers, each You are working as a data analyst for a local community center, where you are tasked with organizing a recreational event for families. To better understand the interests of the families, you've
representing the total sales for a specific product. collected a list of ages of the participants. Your goal is to categorize these ages into two groups: odd and even.
To make informed business decisions, your manager has asked you to find Your manager has asked you to write a program that separates the ages into odd and even numbers and prints both groups separately. This will help in planning activities suitable for different
the second highest sales figure. This will help the team identify the top- age groups.
performing products and understand the sales landscape better.
Your task is to write a Python program that takes a list of sales figures and Input Format:
determines the second highest number in that list. The program will prompt the user to input a list of ages.
The ages should be entered as seperated by comma, which will then be converted into a list of integers.
Input Format: sample input: 1,2,3,4,5,6
The program will prompt the user to input a list of numbers (sales figures)
seperated by comma. Output Format:
The user enter the numbers which will then be converted into a list of The program should print two separate lists: one for the odd ages and one for the even ages.
integers. sample output: even ages:[2,4,6] odd ages:[1,3,5]
sample input: 50,25,10,30,45
Code:
Output Format: ages = list(map(int, input("enter ages seperated by comma: ").split(",")))
The program should print the second highest sales figure in the list. even_ages = []
sample output: 45 odd_ages = []
for age in ages:
Code: if age % 2 == 0:
list_sales = list(map(int, input("enter the numbers seperated by comma: "). even_ages.append(age)
split(","))) else:
set_sales = set(list_sales) odd_ages.append(age)
list_set = list(set_sales) print(f"even ages: {even_ages}")
list_set.sort() print(f"odd ages: {odd_ages}")
print(list_set[-2])
Test Cases:
Test Cases: Test 1: input: 12,15,22,27,34,41,50,61,74 --> output: even ages: [12,22,34,50,74] odd ages: [15,27,41,61]
Test 1: input: 2500,3000,1500,4000,3500 --> output: 3500 Test 2: input: 13,14,17,20,25,47,52 --> output: even ages: [14,20,52] odd ages: [13,17,25,47]
Test 2: input: 13,14,17,52,25,47,52 --> output: 47 Test 3: input: 30,20,15,12,43,51,35 --> output: even ages: [30,20,12] odd ages: [15,43,51,35]
Test 3: input: 12,15,50,27,34,41,50,61,74 --> output: 61 Test 4: input: 1,2,3,4,5,6 --> output: even ages: [1,3,5] odd ages: [2,4,6]
Test 4: input: 123,217,3456,4309,576,685 --> output: 3456 Test 5 :Input: 18,19,20,21,22,23,24 --> Output: even ages: [18,20,22,24] odd ages: [19,21,23]
Test 5 Input: 100,200,300,400,500,600 --> Output: 500 Test 6 :Input: 35,48,56,67,73,88,92 --> Output: even ages: [48,56,88,92] odd ages: [35,67,73]
3 Test 6 :Input: 1200,850,900,1500,1100,1500,700 --> Output: 1200
Imagine you're working on a financial application that processes transactions
for a retail store. Each day, you collect the total sales amounts from different
departments, and you want to quickly find out the total sales for the day. You are a coordinator for a local educational workshop aimed at enhancing student skills. After collecting registrations, you received a list of student names from various schools. To ensure each
Given a list of daily sales amounts from various departments (e.g., [250.50, student is registered only once and to identify any potential duplicates, you need to analyze the list of names.
300.75, 125.00, 450.25]), how would you modify the provided program to Your task is to write a Python program that counts how many times each student's name appears in the list. This will help you ensure that no student is registered more than once and allow you
calculate the total sales for the day? to manage the roster effectively.

Input Format: Input Format:


The program will prompt the user to input a list of numbers (representing The program will prompt the user to input a list of student names.
sales amounts). The names should be entered as seperated by comma, which will then be converted into a list.
The numbers should be entered as a space-separated string, which will then sample input: Alice,Bob,Alice,Charlie,Bob,Alice
be converted into a list of floating-point numbers.
sample input: 10 20 30 40 50 Output Format:
The program should print a dictionary where the keys are student names and the values are the counts of how many times each name appears in the list.
Output Format: sample output: {'alice': 3, 'bob': 2, 'charlie': 1}
The program should calculate the sum of all the sales amounts in the list and
print the total sales for the day. Code:
sample output: 150 student_names = list(map(str, input("enter the student names seperated by comma: ").split(",")))
name_count = {}
Code: for name in student_names:
Transactions = list(map(int, input("enter numbers seperated by space: "). normalized_name = name.lower()
split())) if normalized_name in name_count:
Total = 0 name_count[normalized_name] += 1
for numbers in Transactions: else:
Total += numbers name_count[normalized_name] = 1
print(Total) print(name_count)

Test cases: Test Cases:


Test 1: input: 250.50 300.75 125.00 450.25 --> output: 1126.5 Test 1: input: Alice,Bob,Alice,Charlie,Bob,Alice --> output: {'alice': 3, 'bob': 2, 'charlie': 1}
Test 2: input: 2500 3000 1500 4000 3500 --> output: 14500 Test 2: input: shyam,john,arun,john,shyam --> output: {"shyam": 2, "john": 2, "arun": 1}
Test 3: input: 12 15 22 27 34 41 50 61 74 --> output: 336 Test 3: input: kavya,mansi,moulya,kavya,mansi --> output: {"kavya": 2, "mansi":2, "moulya": 1}
Test 4: input: 123.217 3456.4309 576 685 --> output: 4840.6479 Test 4: input: vedha,navya,kiran,navya --> output: {"vedha": 1, "navya": 2, "kiran":1}
Test 5: input: 1 2 --> output: 3 Test 5: input: ram,ram,sita,sita,sita,lakshman --> output: {"ram": 2, "sita": 3, "lakshman": 1}
4 Test 6: input: 1 -1 0 0.0 0.1 --> output: 0.1 Test 6: input: Tom,Jerry,Spike,Tom,Jerry,Tom --> output: {"tom": 3, "jerry": 2, "spike": 1}
You are developing an educational app that offers a quiz feature to help users test their knowledge on various subjects. To make the quiz more engaging, you want to implement a simple
multiple-choice quiz program. The app should present the user with five multiple-choice questions, track their correct answers, and display their final score at the end.
Your task is to write a Python program that:
1. Displays five multiple-choice questions to the user.
2. Prompts the user to select an answer for each question.
3. Keeps track of the score based on the number of correct answers.
4. Prints the final score after all questions have been answered.

You are developing a text analysis tool for an educational application that Input Format:
helps students improve their reading and writing skills. One of the features is The program presents the user with five multiple-choice questions.
to provide feedback on the vowel usage in their written assignments. For each question, the user will input their choice, typically a letter corresponding to one of the options (e.g., a, b, c, or d).
Given a student’s written paragraph, such as "The quick brown fox jumps sample input:
over the lazy dog.", how would you provide the program to count the number
of vowels in the paragraph? Output Format:
After the user answers all five questions, the program will display the total score based on the number of correct answers.
Input Format:
The program will prompt the user to input a sentence or paragraph. Code:
The input can contain any combination of characters, including spaces and print("Welcome to quiz app")
punctuation. score = 0
sample input: the cute picture print("1.Which planet is known as the Red Planet?")
print("A) Earth B) Mars C) Jupiter D) Venus")
Output Format: answer = input("enter the correct answer: ")
The program should count and print the total number of vowels (a, e, i, o, u) if answer.lower()=="mars":
in the given sentence or paragraph. score+=5
sample output: 6 print("Right answer")
else:
Code: print("wrong answer")
sentence = input("enter the sentence or paragraph to get a count of vowels print("2. Who wrote "Romeo and Juliet"?")
in it: ") print("A) Charles Dickens B) William Shakespeare C) Mark Twain D) Jane Austen")
vowels = "AEIOUaeiou" answer = input("enter the correct answer: ")
count = 0 if answer.lower()=="william shakespeare":
for letter in sentence: score+=5
if letter in vowels: print("Right answer")
count += 1 else:
print(count) print("wrong answer")
print("3.What is the chemical symbol for water?")
Test cases: print("A) O2 B) H2O C) CO2 D) NaCl")
Test 1: input: The quick brown fox jumps over the lazy dog --> output: 11 answer = input("enter the correct answer: ")
Test 2: input: Hello World --> output: 3 if answer.lower()=="h2o":
Test 3: input: The life is beautiful! --> output: 9 score+=5
Test 4: input: number of vowels in the paragraph --> output: 9 print("Right answer")
Test 5: input: This is a good day --> output: 6 else:
Test 6: input: time flies! --> output: 4 print("wrong answer")
5 print(f"Your final score is: {score} out of 15")

You might also like