Cse1005 Question Bank Module 2
Cse1005 Question Bank Module 2
"Problem Statement:
Write a Python program that extracts and outputs the characters at odd
indices (0-based index) of a given string.
Test Cases:
Test Case 1:
Input:
Arijit
Output:
rjt
Explanation: The characters at odd indices (0-based index) are ""r"",
""j"", and ""t"".
Test Case 2:
Input:
priyanka
Output:
ryna
Test Case 3:
Input:
HelloWorld
Output:
elWrd
Test Case 4:
Input:
Python
Output: yhn
Test Case 5:
Input:
Programming
Output: rgamn
Test Case 6:
Input:
MachineLearning
Output: ahnLann
Solution:
input_string = input()
odd_index_characters = """"
for i in range(1, len(input_string), 2): # Start from index 1 and step by 2
(odd indices)
odd_index_characters += input_string[i]
print(odd_index_characters)
"
"""Imagine you are a manager in a clothing store. The store sells three
different types of shirts, and you need to decide which shirt is the most
expensive. The prices of the shirts vary, and your task is to compare
these prices and determine which shirt is the highest-priced so you can
make decisions about sales or promotions.
You have three prices, and the program will help you determine which
one is the largest, indicating the most expensive shirt.
Problem:
Write a program that takes three prices as input and prints the highest
one, helping you identify the most expensive shirt in the store.
Test Cases:
Test Case 1:
Scenario: The prices of three shirts are 4, 7, and 2 dollars. You need to
identify the most expensive shirt.
Input:
4, 7, 2
Output:
7
Test Case 2:
Input:
10, 20, 15
Output:
20
Test Case 3:
Input:
30, 25, 50
Output:
50
Test Case 4:
Input:
5, 5, 5
Output:
5
Test Case 5:
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)
"
"Imagine you're working in a text analysis company that processes user
reviews for a product. Your task is to determine how many times a
specific character appears in a given review text. This information is
useful for sentiment analysis, to understand the frequency of certain
keywords or emotional indicators. For example, if the character ""!""
appears frequently in a review, it might indicate excitement. You need to
create a program that takes a review (string) and a character as input
and returns how many times that character appears in the review.
Problem Statement:
Write a Python program that takes a string and a character as input and
outputs the number of times the character appears in the string.
Test Cases:
Test Case 1:
Input:
Priyanka
a
Output: 2
Explanation: The character 'a' appears twice in ""Priyanka"".
Test Case 2:
Input:
Hello World
l
Output: 3
Test Case 3:
Input:
test Case
t
Output: 2
Test Case 4:
Input:
python programming
p
Output: 2
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 are managing the order of tasks on your daily to-do list.
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
reprioritize tasks for the day, especially when plans change.
Problem:
Write a program that takes a list of n integers (representing tasks or
items) and reverses the order of the list. The solution should not use any
built-in functions such as reverse().
Input Format:
First Line: An integer n, representing the number of elements in the list.
Second Line: A space-separated list of n integers, representing the tasks
or values.
Test Cases:
Test Case 1:
Input:
5
12345
Output:
54321
Test Case 2:
Input:
6
10 20 30 40 50 60
Output:
60 50 40 30 20 10
Test Case 3:
Input:
4
7 14 21 28
Output:
28 21 14 7
Test Case 4:
Input:
3
987
Output:
789
Test Case 5:
Input:
2
100 200
Output:
200 100
Test Case 6:
Input:
1
99
Output:
99
Solution:
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
reversed_arr = []
for i in range(n-1, -1, -1):
reversed_arr.append(arr[i])
for i in reversed_arr:
print(i, end="" "")"
"""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 Cases:
Test Case 1:
Input:
Kalyani Govt. Eng. College
Output: KGEC
Explanation: The first letter of each word is """"K"""", """"G"""", """"E"""",
and """"C"""".
Test Case 2:
Input:
Computer Science and Engineering
Output: CSaE
Test Case 3:
Input:
University of California
Output: UoC
Test Case 4:
Input:
National Institute of Technology
Output: NIoT
Test Case 5:
Input:
Indian Institute of Technology
Output: IIoT
Test Case 6:
Input:
Central Library Management System
Output: CLMS
Solution:
sentence = input()
words = sentence.split()
initials = """"""""
for word in words:
initials += word[0]
print(initials)
"Problem Statement:
Write a Python program that extracts and outputs the characters at odd
indices (0-based index) of a given string.
Input Format Description:
The first line contains a string, which may consist of letters and other
characters.
Example Input:
Arijit
Output Format Description:
The output should be a string containing the characters at the odd
indices (0-based index) of the given string.
Example Output:
rjt
Test Cases:
Test Case 1:
Input:
Arijit
Output:
rjt
Explanation: The characters at odd indices (0-based index) are ""r"",
""j"", and ""t"".
Test Case 2:
Input:
priyanka
Output:
ryna
Test Case 3:
Input:
HelloWorld
Output:
elWrd
Test Case 4:
Input:
Python
Output: yhn
Test Case 5:
Input:
Programming
Output: rgamn
Test Case 6:
Input:
MachineLearning
Output: ahnLann
Solution:
input_string = input()
odd_index_characters = """"
for i in range(1, len(input_string), 2): # Start from index 1 and step by 2
(odd indices)
odd_index_characters += input_string[i]
print(odd_index_characters)
"
"""Imagine you are a manager in a clothing store. The store sells three
different types of shirts, and you need to decide which shirt is the most
expensive. The prices of the shirts vary, and your task is to compare
these prices and determine which shirt is the highest-priced so you can
make decisions about sales or promotions.
You have three prices, and the program will help you determine which
one is the largest, indicating the most expensive shirt.
Problem:
Write a program that takes three prices as input and prints the highest
one, helping you identify the most expensive shirt in the store.
Test Cases:
Test Case 1:
Scenario: The prices of three shirts are 4, 7, and 2 dollars. You need to
identify the most expensive shirt.
Input:
4, 7, 2
Output:
7
Test Case 2:
Input:
10, 20, 15
Output:
20
Test Case 3:
Input:
30, 25, 50
Output:
50
Test Case 4:
Input:
5, 5, 5
Output:
5
Test Case 5:
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)
"
"Imagine you're working in a text analysis company that processes user
reviews for a product. Your task is to determine how many times a
specific character appears in a given review text. This information is
useful for sentiment analysis, to understand the frequency of certain
keywords or emotional indicators. For example, if the character ""!""
appears frequently in a review, it might indicate excitement. You need to
create a program that takes a review (string) and a character as input
and returns how many times that character appears in the review.
Problem Statement:
Write a Python program that takes a string and a character as input and
outputs the number of times the character appears in the string.
Test Cases:
Test Case 1:
Input:
Priyanka
a
Output: 2
Explanation: The character 'a' appears twice in ""Priyanka"".
Test Case 2:
Input:
Hello World
l
Output: 3
Test Case 3:
Input:
test Case
t
Output: 2
Test Case 4:
Input:
python programming
p
Output: 2
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 are managing the order of tasks on your daily to-do list.
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
reprioritize tasks for the day, especially when plans change.
Problem:
Write a program that takes a list of n integers (representing tasks or
items) and reverses the order of the list. The solution should not use any
built-in functions such as reverse().
Input Format:
First Line: An integer n, representing the number of elements in the list.
Second Line: A space-separated list of n integers, representing the tasks
or values.
Test Cases:
Test Case 1:
Input:
5
12345
Output:
54321
Test Case 2:
Input:
6
10 20 30 40 50 60
Output:
60 50 40 30 20 10
Test Case 3:
Input:
4
7 14 21 28
Output:
28 21 14 7
Test Case 4:
Input:
3
987
Output:
789
Test Case 5:
Input:
2
100 200
Output:
200 100
Test Case 6:
Input:
1
99
Output:
99
Solution:
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
reversed_arr = []
for i in range(n-1, -1, -1):
reversed_arr.append(arr[i])
for i in reversed_arr:
print(i, end="" "")"
"""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.
Example Output:
KGEC
Test Cases:
Test Case 1:
Input:
Kalyani Govt. Eng. College
Output: KGEC
Explanation: The first letter of each word is """"K"""", """"G"""", """"E"""",
and """"C"""".
Test Case 2:
Input:
Computer Science and Engineering
Output: CSaE
Test Case 3:
Input:
University of California
Output: UoC
Test Case 4:
Input:
National Institute of Technology
Output: NIoT
Test Case 5:
Input:
Indian Institute of Technology
Output: IIoT
Test Case 6:
Input:
Central Library Management System
Output: CLMS
Solution:
sentence = input()
words = sentence.split()
initials = """"""""
for word in words:
initials += word[0]
print(initials)
-------------------------------------------------------------------
"Imagine you are a teacher analyzing students' grades for a set of
quizzes. You want to calculate the average score for the students, but
you decide to 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 n scores, and the program calculates the
average of the scores between two limits, excluding the scores at those
limits.
Problem:
Write a program that takes n numbers as input (representing student
quiz scores), along with two limit numbers, and calculates the average of
the scores that fall between the two limits, excluding the limits
themselves. The limits are always limit1 and limit2, where limit1 is the
lower bound and limit2 is the upper bound.
Input Format:
First Line: An integer n, representing the number of elements in the list.
Second Line: A space-separated list of n integers, representing the
numbers (e.g., student scores or values).
Third Line: An integer limit1, representing the lower limit (this number
and numbers below it are excluded).
Fourth Line: An integer limit2, representing the upper limit (this number
and numbers above it are excluded).
Test Cases:
Test Case 1:
Input:
5
12345
2
4
3
Explanation: The numbers between limit1 = 2 and limit2 = 4 are 3, so the
average is 3.
Test Case 2:
Input:
6
10 15 20 25 30 35
15
30
Output: 22
Test Case 3:
Input:
5
5 10 15 20 25
10
20
Output: 15
Test Case 4:
Input:
7
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)
"
"Imagine you are working on a project for an e-commerce website. The
website stores product ratings in a list for each product, where
customers can rate a product from 1 to 5. You need to develop a feature
that identifies the highest rating given to a particular product.
For example, if a product has ratings 3 5 4 2 5 you need to identify the
highest rating (which is 5) so that you can highlight this on the product
page.
Test Cases:
Test Case 1:3 5 4 2 1
Output: 5
Explanation: The list contains multiple ratings, and the highest rating is
5.
Test Cases:
Test Case 1:
Input:
Kalyani Goverment Engineering College
Output:
4
Explanation: The string contains 4 words: ""Kalyani"", ""Goverment"",
""Engineering"", and ""College"".
Test Case 2:
Input:
Python Programming Language
Output:
3
Test Case 3:
Input:
This is an example
Output:
4
Test Case 4:
Input:
Cloud computing is awesome
Output: Number of words: 4
Test Case 5:
Input:
Python is a great language
Output: Number of words: 5
Test Case 6:
Input:
I love coding in Python
Output: 5
Solution:
input_string = input()
words = input_string.split()
word_count = len(words)
print(word_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:
Write a Python program that takes two lines of input:
The first line contains the number of trucks (N) – though this number is
just to indicate how many numbers will follow and is not directly used.
The second line contains N integers, representing the number of
deliveries made by each truck.
The program should print all even numbers from the list of deliveries.
Test Cases:
Test Case 1:
Input:
5
12345
Output:
24
Explanation: The even numbers are 2 and 4.
Test Case 2:
4
3279
Output:
2
Test Case 3:
Input:
6
2 4 6 8 10 12
Output: 2 4 6 8 10 12
Test Case 4:
Input:
3
123
Output: 2
Test Case 5:
Input:
5
10 11 12 13 14
Output:
10 12 14
Test Case 6:
Input:
7
0123456
Output:
0246
Solution:
n = int(input())
input_list = input().split()
even_numbers = []
for num in input_list:
num = int(num)
if num % 2 == 0:
even_numbers.append(num)
for even in even_numbers:
print(even, end="" "")"
Problem Statement:
Write a Python program that takes multiple names as input and sorts
them in dictionary (lexical) order. After sorting, the program should
output the names in ascending order.
Test Cases:
Test Case 1:
Input:
3
Arijit
Minaz
Arnab
Output:
Copy code
Arijit
Arnab
Minaz
Explanation: The names sorted in dictionary order are ""Arijit"",
""Arnab"", and ""Minaz"".
Test Case 2:
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)
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
"Test Cases:
Input: 0 → Output: 0
Input: 5 → Output: 6
Input: 15 → Output: 56
Input: 2 → Output: 2
Input: 20 → Output: 110
Input: 1 → Output: 0"
Solution:
Solution:
numbers = list(map(int,input().split()))
unique_numbers = []
for num in numbers:
if num not in unique_numbers:
unique_numbers.append(num)
print(unique_numbers)
"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:
Solution:
Test Cases:
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: []
Solution:
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:
string = input(""Enter a string: "")
vowels = ""aeiouAEIOU""
count = 0
for char in string:
if char in vowels:
count += 1
print(""Number of vowels:"", count)
"
Output Example: Number of vowels: 3
Test Cases:
Input: hello → Output: 2
Input: world → Output: 1
Input: aeiou → Output: 5
Input: bcdfg → Output: 0
Input: The quick brown fox → Output: 5
Input: PYTHON → Output: 0
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:
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"")
else:
print(""Not a Palindrome"")"
Sample Output: "Palindrome"
Test Cases:
Input: "Madam" → Output: "Palindrome"
Input: "Hello World" → Output: "Not a Palindrome"
Input: "Was it a car or a cat I saw" → Output: "Palindrome"
"
Sample Input: "Hello World" "Solution:
sentence = ""Hello World""
vowels = ""aeiouAEIOU""
result = """"
print(result)
# Output: ""H_ll_ W_rld"""
Sample Output: "H_ll_ W_rld"
Test Cases:
Input: "python" → Output: "pyth_n"
Input: "AEIOU" → Output: "_____"
Input: "Python is fun" → Output: "Pyth_n _s f_n"
Input: "Guessing game" → Output: "G_ss_ng g_m_"
Input: "Happy Birthday" → Output: "H_ppy B_rthd_y"
Input: "" → Output: ""
Given a list of words from a document, find and count all duplicate
words.
"Input Format:
"
Sample Input: ["apple", "banana", "apple", "orange", "banana", "apple"]
"Solution:
words = [""apple"", ""banana"", ""apple"", ""orange"", ""banana"",
""apple""]
word_count = {}
duplicate_words = {}
Test Cases:
Input: ["a", "b", "a", "c", "b"] → Output: {"a": 2, "b": 2}
Input: ["hello", "world"] → Output: {}
Input: ["test", "test", "test"] → Output: {"test": 3}
Input: ["x", "y", "z", "x", "y", "z"] → Output: {"x": 2, "y": 2, "z": 2}
Solution:
"
Enter checked-out books: Book2 Book4
Available books: ['Book1', 'Book3']
"Test Cases:
"A teacher needs to assign students to seats, filling available seats from
the front.
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
"Solution:
all_seats = input(""Enter all seats separated by spaces: "").split()
occupied_seats = input(""Enter occupied seats separated by spaces:
"").split()
available_seats = []
Test Cases:
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.
my_list = [4, 1, 7, 3, 9]
maximum = max(my_list)
print(maximum) # Output: 9
Test Cases:
Test 1: my_list = [1, 2, 3] → Output: 3
Test 2: my_list = [5, 4, 3] → Output: 5
Test 3: my_list = [-1, -2, -3] → Output: -1
Test 4: my_list = [10, 10, 10] → Output: 10
Test 5: my_list = [0, 100, -50] → Output: 100
"
"2. Given a list, reverse the order of its elements.
Input Format:
The input will be a list of elements, which could be integers, strings, or
mixed types.
The list will contain at least one element.
Output Format:
The program should output the reversed list.
my_list = [1, 2, 3, 4, 5]
reversed_list = my_list[::-1]
print(reversed_list) # Output: [5, 4, 3, 2, 1]
Test Cases:
Test 1: my_list = [1, 2, 3] → Output: [3, 2, 1]
Test 2: my_list = [5, 10, 15] → Output: [15, 10, 5]
Test 3: my_list = [0, -1, -2] → Output: [-2, -1, 0]
Test 4: my_list = [100] → Output: [100]
Test 5: my_list = [] → Output: []"
"3. Given a list, find the sum of all elements in the list.
Input Format:
The input will be a list of numbers (integers or floating-point numbers).
The list will contain at least one element.
Output Format:
The program should output the sum of all elements in the list.
my_list = [1, 2, 3, 4, 5]
total = sum(my_list)
print(total) # Output: 15
Test Cases:
Input Format:
The input will be a list of integers.
The list will contain at least one integer.
Output Format:
The program should output the maximum integer in the list.
my_list = [4, 1, 7, 3, 9]
maximum = max(my_list)
print(maximum) # Output: 9
Test Cases:
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
vowels in the input string.
print(vowel_count) # Output: 3
Test Cases:
"
Write a program to check if a String Contains All Vowels
Input Format:
The input will be a string that may contain both uppercase and
lowercase characters.
Output Format:
The program should output True if the string contains all the vowels (a,
e, i, o, u), otherwise False.
# Input
s = input(""Enter a string: "").lower()
# Processing
vowels = set(""aeiou"")
contains_all_vowels = vowels.issubset(set(s))
# Output
print(""Contains all vowels:"", contains_all_vowels)
# Test cases
# Input: ""education"" → Output: True
# Input: ""hello"" → Output: False
# Input: ""sequoia"" → Output: True
# Input: ""rhythm"" → Output: False
# 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:
A list of integers, representing the numbers in the list.
An integer target, representing the sum you are looking for.
Output Format:
The program should output all unique pairs of numbers that add up to
the target sum. Each pair should be printed on a new line.
# Input
lst = list(map(int, input(""Enter numbers separated by spaces: "").split()))
target = int(input(""Enter target sum: ""))
# Processing
pairs = []
for i in range(len(lst)):
for j in range(i+1, len(lst)):
if lst[i] + lst[j] == target:
pairs.append((lst[i], lst[j]))
# Output
print(""Pairs that sum to"", target, "":"", pairs)
# Test cases:
# Input: 1 2 3 4 5, 5 → Output: [(1, 4), (2, 3)]
# Input: 10 20 30, 30 → Output: [(10, 20)]
# Input: 5 5 5 5, 10 → Output: [(5, 5), (5, 5), (5, 5)]
# Input: 1 2 3, 6 → Output: []
# Input: 4 4 2 2, 6 → Output: [(4, 2), (4, 2)]"
"Write a program to Check if a String is an Anagram
Input Format:
The input will consist of two strings.
Output Format:
The program should output True if the strings are anagrams of each
other, otherwise False.
# Input
str1 = input(""Enter the first string: "").lower().replace("" "", """")
str2 = input(""Enter the second string: "").lower().replace("" "", """")
# Processing
is_anagram = sorted(str1) == sorted(str2)
# Output
print(""Are anagrams:"", is_anagram)
# Test cases
# Input: ""listen"", ""silent"" → Output: True
# Input: ""hello"", ""world"" → Output: False
# Input: ""dormitory"", ""dirty room"" → Output: True
# Input: ""conversation"", ""voices rant on"" → Output: True
# Input: ""python"", ""typhon"" → Output: True"
"Create Acronym from Sentence.
Input Format:
The input will be a single sentence (a string), consisting of words
separated by spaces.
Output Format:
The program should output a single string, which is the acronym created
from the sentence.
# Input
sentence = input(""Enter a sentence: "")
# Processing
acronym = """"
for word in sentence.split():
acronym += word[0].upper()
# Output
print(""Acronym:"", acronym)
# Test cases
# Input: ""As Soon As Possible"" → Output: ""ASAP""
# Input: ""National Aeronautics and Space Administration"" → Output:
""NASA""
# Input: ""Machine Learning"" → Output: ""ML""
# Input: ""Artificial Intelligence"" → Output: ""AI""
# Input: ""World Health Organization"" → Output: ""WHO""
"
Palindrome Checker
"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
A single line containing a string s consisting of alphanumeric characters
only.
Output Format
Print ""YES"" if the string is a palindrome, otherwise print ""NO"".
Constraints
1≤length of 𝑠≤10^5
1≤length of s≤10^5
The string contains only lowercase letters (a-z) and/or digits (0-9).
Sample Input 0
madam
Sample Output 0
YES
Sample Input 1
hello
Sample Output 1
NO
code:
s = input().strip()
if s == s[::-1]:
print(""YES"")
else:
print(""NO"")
Testcase 1:
Input:
abcdefgh
Output:
NO
Testcase 2:
Input:
aabbcbbaa
Output:
YES
Testcase 3:
Input:
a...a (100,000 ""a"" characters)
Output:
YES
Testcase 4:
Input:
abccbx
Output:
NO"
"
List Comprehensions"
"You are given an integer N. Use list comprehension to create a list that
contains the squares of all numbers from 1 to N (inclusive).
Write a Python program that generates the list of squares using list
comprehension.
Input:
A single integer N (1 ≤ N ≤ 1000)
Output:
A list containing the squares of numbers from 1 to N, inclusive.
Input:
5
Output:
[1, 4, 9, 16, 25]
code:
N = int(input())
squares = [x**2 for x in range(1, N+1)]
print(squares)
Test Case 1:
Input:
3
Output:
[1, 4, 9]
Test Case 2:
Input:
5
Output:
[1, 4, 9, 16, 25]
Test Case 3:
Input:
1
Output:
[1]
Test Case 4:
Input:
10
Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Test Case 5:
Input:
8
Output:
[1, 4, 9, 16, 25, 36, 49, 64]"
Sum of Even and Odd Elements
"Given a list of integers, calculate the sum of even numbers and the sum
of odd numbers separately.
Input Format
The first line contains an integer n, the number of elements in the list.
The second line contains n space-separated integers.
Output Format
Print two space-separated integers: the sum of even numbers and the
sum of odd numbers.
Sample Input
5
12345
Sample Output
69
code:
n = int(input())
arr = list(map(int, input().split()))
even_sum = 0
odd_sum = 0
for num in arr:
if num % 2 == 0:
even_sum += num
else:
odd_sum += num
print(even_sum, odd_sum)
Test Case 1
Input:
3
123
Output:
24
Test Case 2
Input:
4
10 15 20 25
Output:
30 40
Test Case 3
Input:
6
-1 -2 -3 -4 -5 -6
Output:
-12 -9
Test Case 4
Input:
5
2 4 6 8 10
Output:
30 0
Test Case 5
Input:
5
13579
Output:
0 25
"
Multiply All Elements in a List
"You are given a list of integers. Your task is to calculate the product of
all elements in the list and print the result.
Input Format
The first line contains an integer, n, the number of elements in the list.
The second line contains n space-separated integers, representing the
elements of the list.
Output Format
Print the product of all elements in the list.
Constraints
1≤𝑛≤10^3
−10^3≤element≤10^3
Sample Input 1
4
1234
Sample Output 1
24
code:
n = int(input())
numbers = list(map(int, input().split()))
product = 1
for num in numbers:
product *= num
print(product)
Testcase1:
input :
4
5555
Output:
625
Testcase 2:
Input
4
0123
Output
0
Testcase 3:
Input
4
-1 2 -3 4
Output
24
Testcase 4:
Input
1
10
Output
10
"
Count Occurrences of Each Element
"Given a list of integers, count the occurrences of each element and
display them.
Input Format
The first line contains an integer n, the number of elements in the list.
The second line contains n space-separated integers.
Output Format
Print each unique element followed by its count, in the order of their first
appearance.
Sample Input
7
1223334
Sample Output
11
22
33
41
code:
n = int(input())
numbers = list(map(int, input().split()))
unique_elements = []
occurrences = {}
for num in numbers:
if num not in occurrences:
occurrences[num] = 1
unique_elements.append(num) # Keep track of the first
appearance order
else:
occurrences[num] += 1
for num in unique_elements:
print(num, occurrences[num])
Test Case 1:
Input:
5
55555
Output:
55
Test Case 2:
Input:
4
10 20 20 30
Output:
10 1
20 2
30 1
Test Case 3:
Input:
6
111111
Output:
16
Test Case 4:
Input:
8
45467888
Output:
42
51
61
71
83
Test Case 5:
Input:
10
9876543210
Output:
91
81
71
61
51
41
31
21
11
0 1"
"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 separated by a comma.
The program will process this list, remove duplicate titles, and preserve
the original order.
sample input: Physics,chemistry,signals,physics
Output Format:
The program should print a list of book titles, with each title appearing
only once, and the order should be preserved as in the original input.
sample output: [""Physics"", ""chemistry"", ""signals""]
Code:
List = list(map(str, input(""enter the book titles seperated by comma :
"").split("","")))
L=[]
for book in List:
if book not in L:
L.append(book)
print(L)
Test Cases:
Test 1: input: M1,M2,M1,M3,M2 --> output: [""M1"",""M2"",""M3""]
Test 2: input: Physics,chemistry,signals,physics --> output:
[""Physics"",""chemistry"",""signals""]
Test 3: input: a,b,c,a,c --> output: ['a','b','c']
Test 4: input: 1,a,2,b,1,2 --> output: [""1"",""a"",""2"",""b""]
Test 5: input: c,a,c,t,a --> output: ['c','a','t']
Test 6: Input: apple,banana,apple,orange,banana,grape --> Output:
[""apple"",""banana"",""orange"",""grape""]
Test 7: Input: 5, 3, 5, 7, 9, 3, 7, 10 --> Output:
[""5"",""3"",""7"",""9"",""10""]
"
"Imagine you're working for an e-commerce platform and have been
asked to 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 how many items the user has selected in their cart.
The goal is to write a Python program that will count the number of items
in 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.
input format:
Take a list of items seperated by comma representing products in the
shopping cart.
Count the number of items in the cart.
sample input: laptophe,adphones,mouse,keyboard
output format:
Print the total number of items.
sample output: 4
test cases:
input: laptop,headphones,mouse --> output: 3
input: --> output:
input: apple,banana,apple,orange --> output: 4
input: t-shirt --> output: 1
input: laptop,headphones --> output: 2
input: phone case,phone case,phone case --> output: 3"
"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 representing the total sales for a specific product.
To make informed business decisions, your manager has asked you to
find the second highest sales figure. This will help the team identify the
top-performing products and understand the sales landscape better.
Your task is to write a Python program that takes a list of sales figures
and determines the second highest number in that list.
Input Format:
The program will prompt the user to input a list of numbers (sales
figures) seperated by comma.
The user enter the numbers which will then be converted into a list of
integers.
sample input: 50,25,10,30,45
Output Format:
The program should print the second highest sales figure in the list.
sample output: 45
Code:
list_sales = list(map(int, input(""enter the numbers seperated by comma:
"").split("","")))
set_sales = set(list_sales)
list_set = list(set_sales)
list_set.sort()
print(list_set[-2])
Test Cases:
Test 1: input: 2500,3000,1500,4000,3500 --> output: 3500
Test 2: input: 13,14,17,52,25,47,52 --> output: 47
Test 3: input: 12,15,50,27,34,41,50,61,74 --> output: 61
Test 4: input: 123,217,3456,4309,576,685 --> output: 3456
Test 5 Input: 100,200,300,400,500,600 --> Output: 500
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.
Given a list of daily sales amounts from various departments (e.g.,
[250.50, 300.75, 125.00, 450.25]), how would you modify the provided
program to calculate the total sales for the day?
Input Format:
The program will prompt the user to input a list of numbers (representing
sales amounts).
The numbers should be entered as a space-separated string, which will
then be converted into a list of floating-point numbers.
sample input: 10 20 30 40 50
Output Format:
The program should calculate the sum of all the sales amounts in the list
and print the total sales for the day.
sample output: 150
Code:
Transactions = list(map(int, input(""enter numbers seperated by space:
"").split()))
Total = 0
for numbers in Transactions:
Total += numbers
print(Total)
Test cases:
Test 1: input: 250.50 300.75 125.00 450.25 --> output: 1126.5
Test 2: input: 2500 3000 1500 4000 3500 --> output: 14500
Test 3: input: 12 15 22 27 34 41 50 61 74 --> output: 336
Test 4: input: 123.217 3456.4309 576 685 --> output: 4840.6479
Test 5: input: 1 2 --> output: 3
Test 6: input: 1 -1 0 0.0 0.1 --> output: 0.1"
"You are developing a text analysis tool for an educational application
that helps students improve their reading and writing skills. One of the
features is to provide feedback on the vowel usage in their written
assignments.
Given a student’s written paragraph, such as ""The quick brown fox
jumps over the lazy dog."", how would you provide the program to count
the number of vowels in the paragraph?
Input Format:
The program will prompt the user to input a sentence or paragraph.
The input can contain any combination of characters, including spaces
and punctuation.
sample input: the cute picture
Output Format:
The program should count and print the total number of vowels (a, e, i,
o, u) in the given sentence or paragraph.
sample output: 6
Code:
sentence = input(""enter the sentence or paragraph to get a count of
vowels in it: "")
vowels = ""AEIOUaeiou""
count = 0
for letter in sentence:
if letter in vowels:
count += 1
print(count)
Test cases:
Test 1: input: The quick brown fox jumps over the lazy dog --> output:
11
Test 2: input: Hello World --> output: 3
Test 3: input: The life is beautiful! --> output: 9
Test 4: input: number of vowels in the paragraph --> output: 9
Test 5: input: This is a good day --> output: 6
Test 6: input: time flies! --> output: 4
Input Format:
The input will consist of a list of elements, which could be integers,
strings, or any other type.
The list will contain at least one element.
Output Format:
The program should output True if the list is a palindrome.
Otherwise, the program should output False.
my_list = [1, 2, 3, 2, 1]
is_palindrome = my_list == my_list[::-1]
print(is_palindrome) # Output: True
Test Cases:
my_list = [1, 2, 2, 3, 3, 3]
duplicates = list(set([x for x in my_list if my_list.count(x) > 1]))
print(duplicates) # Output: [2, 3]
Test Cases:
Input Format:
The input will be a string that may contain spaces.
Output Format:
The program should output a string where all spaces are replaced by
hyphens (-).
my_string = ""hello world""
replaced_string = my_string.replace("" "", ""-"")
print(replaced_string) # Output: hello-world
Test Cases:
Input Format:
The input will be a single string that may contain letters, digits, spaces,
and punctuation marks.
The program should ignore spaces, punctuation, and capitalization when
checking for palindromes.
Output Format:
The program should output True if the string is a palindrome, otherwise
False.
my_string = ""madam""
is_palindrome = my_string == my_string[::-1]
print(is_palindrome) # Output: True
Test Cases:
Test 1: my_string = ""level"" → Output: True
Test 2: my_string = ""world"" → Output: False
Test 3: my_string = ""racecar"" → Output: True
Test 4: my_string = ""hello"" → Output: False
Test 5: my_string = ""a"" → Output: True
"
nput Format:
The input will be a string that can contain both uppercase and lowercase
letters.
Output Format:
The program should output the longest palindromic substring.
# Input
s = input(""Enter a string: "")
# Processing
n = len(s)
longest_palindrome = """"
for i in range(n):
for j in range(i, n):
substring = s[i:j+1]
if substring == substring[::-1] and len(substring) >
len(longest_palindrome):
longest_palindrome = substring
# Output
print(""Longest palindromic substring:"", longest_palindrome)
# Test cases
# Input: ""babad"" → Output: ""bab"" or ""aba""
# Input: ""cbbd"" → Output: ""bb""
# Input: ""forgeeksskeegfor"" → Output: ""geeksskeeg""
# Input: ""racecar"" → Output: ""racecar""
# Input: ""a"" → Output: ""a""
"
"Write a program to find the First Non-Repeating Character in python
Input Format:
The input will be a string containing alphanumeric characters (letters and
digits).
Output Format:
The program should output the first non-repeating character in the string,
or -1 if there is no non-repeating character.
# Input
s = input(""Enter a string: "")
# Processing
for char in s:
if s.count(char) == 1:
first_non_repeating = char
break
else:
first_non_repeating = None
# Output
print(""First non-repeating character:"", first_non_repeating)
# Test cases
# Input: ""swiss"" → Output: ""w""
# Input: ""hello"" → Output: ""h""
# Input: ""aabbcc"" → Output: None
# Input: ""programming"" → Output: ""p""
# 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
max_len = 1
current_len = 1
longest_value = lst[0]
for i in range(1, len(lst)):
if lst[i] == lst[i-1]:
current_len += 1
else:
if current_len > max_len:
max_len = current_len
longest_value = lst[i-1]
current_len = 1
if current_len > max_len:
longest_value = lst[-1]
# Output
print(""Longest sublist element:"", longest_value, ""Length:"", max_len)
# Test cases:
# Input: 1 1 2 2 2 3 → Output: 2, Length: 3
# Input: 5 5 5 5 6 7 → Output: 5, Length: 4
# Input: 1 1 1 1 1 → Output: 1, Length: 5
# Input: 9 9 9 8 8 → Output: 9, Length: 3
# Input: 7 8 9 9 → Output: 9, Length: 2
"
"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:
A list of integers (can include positive and negative numbers).
A target sum (integer).
Output Format:
The program should output all pairs of numbers (in the form of tuples)
that sum to the target sum.
# Input
lst = list(map(int, input(""Enter numbers separated by spaces: "").split()))
target = int(input(""Enter target sum: ""))
# Processing
pairs = []
for i in range(len(lst)):
for j in range(i+1, len(lst)):
if lst[i] + lst[j] == target:
pairs.append((lst[i], lst[j]))
# Output
print(""Pairs that sum to"", target, "":"", pairs)
# Test cases:
# Input: 1 2 3 4 5, 5 → Output: [(1, 4), (2, 3)]
# Input: 10 20 30, 30 → Output: [(10, 20)]
# Input: 5 5 5 5, 10 → Output: [(5, 5), (5, 5), (5, 5)]
# Input: 1 2 3, 6 → Output: []
# Input: 4 4 2 2, 6 → Output: [(4, 2), (4, 2)]
"
"
Count Vowels and Consonants"
"
Write a program to count the number of vowels and consonants in a
given string.
Input Format
A single line containing a string s (consisting of alphabetic characters
only).
Output Format
Print two space-separated integers: the number of vowels and the
number of consonants in the string.
Constraints
1≤length of 𝑠≤10^5
1≤length of s≤10^5
The string s contains only lowercase letters (a-z).
Sample Input 0
hello
Sample Output 0
23
code:
s = input().strip()
vowels = 0
consonants = 0
vowel_set = {'a', 'e', 'i', 'o', 'u'}
for char in s:
if char in vowel_set:
vowels += 1
else:
consonants += 1
print(vowels, consonants)
Test Case 1
Input:
abcde
Output:
23
Test Case 2
Input:
aeiou
Output:
50
Test Case 3
Input:
bcdfghjklmnpqrstvwxyz
Output:
0 21
Test Case 4
Input:
programming
Output:
3 8"
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()))
k = int(input())
k=k%n
rotated_list = arr[-k:] + arr[:-k]
print("" "".join(map(str, rotated_list)))
Test Case 1:
Input:
7
10 20 30 40 50 60 70
3
Output:
50 60 70 10 20 30 40
Test Case 2:
Input:
5
12345
0
Output:
12345
Test Case 3:
Input:
6
123456
6
Output:
123456
Test Case 4:
Input:
4
10 20 30 40
1
Output:
40 10 20 30
Test Case 5:
Input:
3
5 10 15
4
Output:
10 15 5"
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
1≤𝑛≤10^5
1≤n≤10^5
Each integer in the list is unique and within the range from 1 to n.
Output Format
Print the missing numbers in ascending order, separated by spaces.
If no numbers are missing, print No missing numbers.
Sample Input
6
1246
Sample Output
35
code:
n = int(input())
numbers = list(map(int, input().split()))
missing_numbers = []
if missing_numbers:
print("" "".join(map(str, missing_numbers)))
else:
print(""No missing numbers"")
Test Case 1:
Input:
5
54321
Output:
No missing numbers
Test Case 2:
Input:
10
124579
Output:
3 6 8 10
Test Case 3:
Input:
3
13
Output:
2
Test Case 4:
Input:
7
7654321
Output:
No missing numbers
Test Case 5:
Input:
4
123
Output:
4
"
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:
A single line containing space-separated integers.
Constraints:
The list will contain at least two numbers.
Output Format:
Return the second largest unique number.
Sample Input:
10 20 4 45 99 99
Sample Output:
45
code:
numbers = list(map(int, input().split()))
numbers.sort(reverse=True)
for i in range(1, len(numbers)):
if numbers[i] != numbers[0]:
print(numbers[i])
break
Test Case 1:
Input:
15 10 15 20 25 25 30
Output:
25
Test Case 2:
Input:
5 5 10 10 5
Output:
5
Test Case 3:
Input:
8273743
Output:
4
Test Case 4:
Input:
1312
Output:
2
Test Case 5:
Input:
99 55 33 99 55
Output:
55
"
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:
Input Format:
A single line containing 7 space-separated integers representing the
temperatures recorded each day.
Output Format:
First line: Print the highest temperature.
Second line: Print the lowest temperature.
Third line: Print the average temperature (rounded to two decimal
places).
Fourth line: Print the day number with the highest temperature in this
format: Day X.
Constraints
There are exactly 7 temperatures (one for each day of the week).
Each temperature is an integer.
Sample Input
25 28 31 29 30 32 27
Sample Output
32
25
28.86
Day 6
code:
print(highest_temp)
print(lowest_temp)
print(f""{average_temp:.2f}"")
print(f""Day {highest_temp_day}"")
Test Case 1
Input:
25 28 31 29 30 32 27
Output:
32
25
28.86
Day 6
Test Case 2
Input:
20 20 20 20 20 20 20
Output:
20
20
20.00
Day 1
Test Case 3
Input:
15 30 25 28 34 29 20
Expected Output:
34
15
25.86
Day 5
Test Case 4
Input:
10 50 10 50 10 50 10
Output:
50
10
27.14
Day 2
Test Case 5
Input:
32 28 33 27 35 31 29
Output:
35
27
30.71
Day 5"
Input Format:
The program will prompt the user to input a word or phrase.
The user can enter a string that may include spaces, punctuation, and
different letter case (upper or lower).
sample input1: ""malayalam, malayalam""
sample input2: ""john""
Output Format:
The program should print a message ""palindrome"" if it is palindrome
and ""not a palindrome"" otherwise.
sample output1: palindrome
sample output2: not a palindrome
Code:
user_input = input(""Please enter a word or phrase: "")
words = """".join(char.lower() for char in user_input if char.isalnum())
if words == words[::-1]:
print(""palindrome."")
else:
print(""not a palindrome."")
Test Cases:
Test 1: input: a man, a plan, a canal, Panama --> output: palindrome
Test 2: input: race car --> output: palindrome
Test 3: input: the holy book --> output: not a palindrome
Test 4: input: the first book --> output: not a palindrome
Test 5: Input: No lemon, no melon --> Output: palindrome
Test 6: Input: Hello World --> Output: not a palindrome
"
"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).
sample input: cake
Output Format:
The program will print the modified string where all vowels (a, e, i, o, u)
have been replaced with the symbol ""_"".
sample output: c_k_
Code:
word = input(""enter the string: "")
vowels = ""AEIOUaeiou""
w = """"
for letter in word:
if letter in vowels:
w=w+""_""
else:
w=w+letter
print(w)
Test Cases:
Test 1: input: hello world --> output: h_ll_ w_rld
Test 2: input: python --> output: pyth_n
Test 3: input: Alphabets --> output: _lph_b_ts
Test 4: input: TRAINER --> output: TR_ _N_R
Test 5: input: presidency --> output: pr_s_d_ncy
Test 6: Input: umbrella --> Output: _mbr_ll_
Test 7: Input: Programming --> Output: Pr_gr_mm_ng"
"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 collected a list of
ages of the participants. Your goal is to categorize these ages into two
groups: odd and even.
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 age groups.
Input Format:
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.
sample input: 1,2,3,4,5,6
Output Format:
The program should print two separate lists: one for the odd ages and
one for the even ages.
sample output: even ages:[2,4,6] odd ages:[1,3,5]
Code:
ages = list(map(int, input(""enter ages seperated by comma:
"").split("","")))
even_ages = []
odd_ages = []
for age in ages:
if age % 2 == 0:
even_ages.append(age)
else:
odd_ages.append(age)
print(f""even ages: {even_ages}"")
print(f""odd ages: {odd_ages}"")
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 2: input: 13,14,17,20,25,47,52 --> output: even ages: [14,20,52]
odd ages: [13,17,25,47]
Test 3: input: 30,20,15,12,43,51,35 --> output: even ages: [30,20,12]
odd ages: [15,43,51,35]
Test 4: input: 1,2,3,4,5,6 --> output: even ages: [1,3,5] odd ages:
[2,4,6]
Test 5 :Input: 18,19,20,21,22,23,24 --> Output: even ages: [18,20,22,24]
odd ages: [19,21,23]
Test 6 :Input: 35,48,56,67,73,88,92 --> Output: even ages: [48,56,88,92]
odd ages: [35,67,73]
"
"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 student is
registered only once and to identify any potential duplicates, you need to
analyze the list of names.
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 to manage the roster
effectively.
Input Format:
The program will prompt the user to input a list of student names.
The names should be entered as seperated by comma, which will then
be converted into a list.
sample input: Alice,Bob,Alice,Charlie,Bob,Alice
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.
sample output: {'alice': 3, 'bob': 2, 'charlie': 1}
Code:
student_names = list(map(str, input(""enter the student names seperated
by comma: "").split("","")))
name_count = {}
for name in student_names:
normalized_name = name.lower()
if normalized_name in name_count:
name_count[normalized_name] += 1
else:
name_count[normalized_name] = 1
print(name_count)
Test Cases:
Test 1: input: Alice,Bob,Alice,Charlie,Bob,Alice --> output: {'alice': 3,
'bob': 2, 'charlie': 1}
Test 2: input: shyam,john,arun,john,shyam --> output: {""shyam"": 2,
""john"": 2, ""arun"": 1}
Test 3: input: kavya,mansi,moulya,kavya,mansi --> output: {""kavya"":
2, ""mansi"":2, ""moulya"": 1}
Test 4: input: vedha,navya,kiran,navya --> output: {""vedha"": 1,
""navya"": 2, ""kiran"":1}
Test 5: input: ram,ram,sita,sita,sita,lakshman --> output: {""ram"": 2,
""sita"": 3, ""lakshman"": 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.
Input Format:
The program presents the user with five multiple-choice questions.
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).
sample input:
Output Format:
After the user answers all five questions, the program will display the
total score based on the number of correct answers.
Code:
print(""Welcome to quiz app"")
score = 0
print(""1.Which planet is known as the Red Planet?"")
print(""A) Earth B) Mars C) Jupiter D) Venus"")
answer = input(""enter the correct answer: "")
if answer.lower()==""mars"":
score+=5
print(""Right answer"")
else:
print(""wrong answer"")
print(""2. Who wrote ""Romeo and Juliet""?"")
print(""A) Charles Dickens B) William Shakespeare C) Mark Twain D)
Jane Austen"")
answer = input(""enter the correct answer: "")
if answer.lower()==""william shakespeare"":
score+=5
print(""Right answer"")
else:
print(""wrong answer"")
print(""3.What is the chemical symbol for water?"")
print(""A) O2 B) H2O C) CO2 D) NaCl"")
answer = input(""enter the correct answer: "")
if answer.lower()==""h2o"":
score+=5
print(""Right answer"")
else:
print(""wrong answer"")
print(f""Your final score is: {score} out of 15"")"