Cse1005 - Sample - Questions - Module - 2
Cse1005 - Sample - Questions - Module - 2
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
Solution:
text = input()
char = input()
count = 0
for c in text:
if c == char:
count += 1
print(count)
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.
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 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
The first line contains a string string (1 ≤ length of string ≤ 1000) in which vowels need to be counted.
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 = ""
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.
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.
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:
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: []
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.
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: 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)
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)
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
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")
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
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.
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")