Cse1005 Question Bank Module 1
Cse1005 Question Bank Module 1
Input: an Integer N
N (1 ≤ N ≤ 1000)
Output:
The sum of the first 𝑁
Test Cases:
Input: 5
Output: 15
Explanation:
1+2+3+4+5=15
Input: 10
Output: 55
Explanation:
55
1+2+3+...+10=55
Input: 1
Output: 1
Input: 20
Output: 210
Input: 100
Output: 5050
Input: 1000
Output: 500500
Question 2: Count Digits in a Number
Problem Statement:
Write a program to count the number of digits in a given positive integer
𝑁.
.
Input:
An integer 𝑁
N (1 ≤ 𝑁 ≤ 100000000000)
Output:
The number of digits in 𝑁
Test Cases:
Input: 12345
Output: 5
Input: 100000
Output: 6
Input: 9
Output: 1
Input: 456789
Output: 6
Input: 1000000000
Output: 10
Input: 987654321
Output: 9
Question 3: Print Even Numbers in a Range
Problem Statement:
Write a program to print all even numbers from 0 to A
Input:
Integer A
(0 >A≤1000)
Output:
All even numbers between 0 to 𝐴 has to be separated by a space.
Test Cases:
Input: 10
Output: 2 4 6 8 10
Input: 15
Output: 6 8 10 12 14
Input: 20
Output: 2 4 6 8 10 12 14 16 18 20
Input: 8
Output: 2 4 6 8
Input: 7
Output: 2 4 6
Input: 2
Output: 2
Question: Count Vowels in a String
Problem Statement:
Write a program to count the number of vowels (a, e, i, o, u) in a given
string
𝑆
S.
Input:
A string
𝑆
S containing lowercase English alphabets (1 ≤ length of 𝑆 ≤ 100).
Output:
The number of vowels in the string 𝑆.
Test Cases:
Input: hello
Output: 2
Explanation: The vowels in hello are e and o, so the count is 2.
Input: bye
Output: 1
Explanation: The vowels in openai are o, e, a, i, so the count is 1.
Input: abcde
Output: 2
Explanation: The vowels in abcde are a and e, so the count is 2.
Input: ai
Output: 2
Explanation: The vowels in ai are a and i, so the count is 2.
Input: xyz
Output: 0
Explanation: There are no vowels in xyz, so the count is 0.
Input: python
Output: 1
Explanation: The only vowel in python is o, so the count is 1
Input:
An integer 𝑁
N (1 ≤ 𝑁 ≤ 10^6)
Output:
The sum of the digits of 𝑁.
Test Cases:
Input: 123
Output: 6
Explanation:
1+2+3=6
Input: 4567
Output: 22
Explanation:
4+5+6+7=22
Input: 1001
Output: 2
Explanation:
1+0+0+1=2
Input: 9999
Output: 36
Explanation:
9+9+9+9=36
Input: 54321
Output: 15
Explanation:
5+4+3+2+1=15
Input: 1
Output: 1
Question: Neon Number Check
Problem Statement:
Write a program to check if a given number 𝑁 is a Neon Number.
A Neon Number is defined as a number where
the sum of the digits of its square is equal to the number itself.
Input:
An integer 𝑁
N (1 ≤ 𝑁 ≤10000)
Output:
Yes if 𝑁
N is a Neon Number; otherwise, output No.
Test Cases:
Input: 9
Output: Yes
Explanation:
9^2 = 81
->8+1=9
Input: 1
Output: Yes
Explanation:
1^2 = 1
Input: 10
Output: No
Explanation:
10^2 =100
-> 1+0+0=1, which is not equal to 10.
Input: 7
Output: No
Explanation:
7^2 = 49
4+9=13, which is not equal to 7.
Input: 45
Output: No
Explanation:
45^2 = 2025
2+0+2+5=9, which is not equal to 45.
Input: 3
Output: No
Explanation:
3^2 =9
-> 9, which is not equal to 3.
Question: Separate Even and Odd Numbers from a List
Problem Statement:
Given a list of integers, separate the even numbers and odd numbers
into two separate lists.
Input:
A list of integers, for example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Output:
Two lists: one containing all the even numbers and one containing all the
odd numbers from the input list.
Test Cases:
Input:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Output:
Even numbers: []
Odd numbers: [11, 13, 17, 19]
Input: [2, 4, 6, 8, 10]
Output:
Input:
An integer 𝑁
N (2 ≤ 𝑁≤1000).
Output:
Yes if 𝑁 is a prime number; otherwise, output No.
Test Cases:
Input: 7
Output: Yes
Input: 10
Output: No
Input: 13
Output: Yes
Input: 4
Output: No
Input: 29
Output: Yes
Input: 100
Output: No
Problem Statement:
You need to calculate the total cost of items in a shopping cart after
applying a discount. First, apply the initial discount based on the
specified percentage. If the total cost after this initial discount exceeds
₹100, apply an additional discount of 10% to the total.
Input Format:
The first line contains an integer N (the number of items in the cart).
The next N lines each contain a floating-point number representing the
price of each item.
The last line contains a floating-point number representing the discount
percentage.
Output Format:
Sample Input:
3
50 . 0
30 . 0
25
20
Sample output :
84 . 0
TESTCASE - 1
INPUT
4
60
40
30
20
10
OUTPUT
121.5
TESTCASE - 2
INPUT
5
100
50
20
10
5
15
OUTPUT
141.5
TESTCASE - 3
INPUT
4
129
879
560
156
10
OUTPUT
1396.4
TESTCASE - 4
INPUT
3
190
540
632
12
OUTPUT
1078.7
MEDIUM LEVEL
first and last guy
Problem Statement:
write a program to sum the frst two and last two digit of a number
Input Format:
The first line contains an integer N
constrains :
9<N<=10^12
Output Format:
sum as integer
Sample Input:
65165
Sample output :
22
TESTCASE - 1
INPUT
123456
OUTPUT
14
TESTCASE - 2
INPUT
123456
OUTPUT
14
TESTCASE - 3
INPUT
123457
OUTPUT
15
TESTCASE - 4
INPUT
875612
OUTPUT
18
Leap Year
Problem Statement:
Write a program to check whether the given year is a leap year or not
Input Format:
Output Format:
Sample Input:
1999
Sample output :
Not Leap YeaR
TESTCASE - 1
INPUT
2024
OUTPUT
Leap YeaR
TESTCASE - 2
INPUT
1900
OUTPUT
Not Leap YeaR
TESTCASE - 3
INPUT
2000
OUTPUT
Leap YeaR
TESTCASE - 4
INPUT
2009
OUTPUT
Not Leap YeaR
Input Format:
Output Format:
Sample Input:
65841520
Sample output :
3
4
TESTCASE - 1
INPUT
88888
OUTPUT
0
5
TESTCASE - 2
INPUT
333333
OUTPUT
6
0
TESTCASE - 3
INPUT
1234567
OUTPUT
4
3
TESTCASE - 4
INPUT
1357924680
OUTPUT
5
4
PRIME NUMBER
Problem Statement:
Take an integer and print "YES" if the integer is prime and "NO" if it is
not.
Input Format:
Output Format:
YES OR NO
Sample Input:
Sample output :
NO
TESTCASE - 1
INPUT
88888
OUTPUT
NO
TESTCASE - 2
INPUT
79
OUTPUT
YES
TESTCASE - 3
INPUT
97
OUTPUT
YES
TESTCASE - 4
INPUT
111
OUTPUT
NO
You are given two integers, start and end, where start is strictly less than
end. Your task is to compute the absolute value of the sum of all
integers between start and end (exclusive). In other words, you need to
subtract each integer from the sum of all integers in the range from
start+1 to end (inclusive).
Input Format:
single line contains two space seperated values start and end
Output Format:
Sample Input:
1
10
Sample output :
54
TESTCASE - 1
INPUT
10
100
OUTPUT
4995
TESTCASE - 2
INPUT
200
500
OUTPUT
105150
TESTCASE - 3
INPUT
-1
100
OUTPUT
5050
TESTCASE - 4
INPUT
-50
50
OUTPUT
50
MEDIUM LEVEL
Fibonacci number
Problem Statement:
Find the nth fibonacci number of a sequence
Input Format:
The first line contains an integer N
Output Format:
Sample Input:
5
Sample output :
3
TESTCASE - 1
INPUT
5
OUTPUT
3
TESTCASE - 2
INPUT
100
OUTPUT
218922995834555169026
TESTCASE - 3
INPUT
20
OUTPUT
4181
TESTCASE - 4
INPUT
10
OUTPUT
34
MEDIUM LEVEL
TWISTED PRODUCT
Problem Statement:
Take two numbers and find sum of all numbers between them that
satisfy following condition (inclusive range):
-> Second last digit of number is 4
Input Format:
Two lines of input each containing a single integer.
FIRST VALUE INDICATES START VALUE OF RANGE
SECOND VALUE INDIACTES END VALUE OF RANGE
Output Format:
A single integer which is the product of all such numbers which follow
the above mentioned conditions.
Sample Input:
30
40
Sample output :
40
TESTCASE - 1
INPUT
10
100
OUTPUT
221
TESTCASE - 2
INPUT
10
200
OUTPUT
941
TESTCASE - 3
INPUT
100
200
OUTPUT
721
TESTCASE - 4
INPUT
100
1000
OUTPUT
24481
MEDIUM LEVEL
SPECIAL NUMBER
Problem Statement:
Take an integer as input and print 'YES' if the number is a special
number. Otherwise, print 'NO'.
Hint:
A special number is a number which is equal to the sum of the factorials
of its digits.
Example:
For number = 145, the output should be 1! + 4! + 5! = 145
Hence 145 is a special number.
Input Format:
The first line contains an integer N
Output Format:
YES OR NO
TESTCASE - 1
INPUT
143
OUTPUT
NO
TESTCASE - 2
INPUT
40585
OUTPUT
YES
TESTCASE - 3
INPUT
6451
OUTPUT
NO
TESTCASE - 4
INPUT
1
OUTPUT
YES
MEDIUM LEVEL
ARMSTRONG OR NOT
Problem Statement:
Write a program to take a number from the input and print whether or not
it's an armstrong number. 153 = (1*1*1)+(5*5*5)+(3*3*3) sample two:
8208=> (8**4)+(2**4)+(0**4)+(8**4)=>8208
Input Format:
The first line contains an integer N
Output Format:
YES OR NO
Sample Input:
153
sample output:
YES
TESTCASE - 1
INPUT
123
OUTPUT
NO
TESTCASE - 2
INPUT
370
OUTPUT
YES
TESTCASE - 3
INPUT
371
OUTPUT
YES
TESTCASE - 4
INPUT
152
OUTPUT
NO
Input:153
Output:Armstrong
Test Case 2:-
Input:370
Output:Armstrong
Input:123
Output:Not Armstrong
2.Imagine a group of friends, Sarah, Mike, and Lucy, who went out to
dinner together. They had a great time chatting and sharing stories, and
when the bill came, they wanted to split it fairly and even leave a nice tip
for the service. Sarah suggested using a bill calculator that she had
recently learned about in her programming class.
The calculator first asks them what the bill amount is, then what
percentage of tip they’d like to leave (they decided between 10, 20, or
30%), and finally, how many people will split the bill. Once they enter all
this information, the calculator tells them the total bill, including the tip,
and how much each person needs to pay.,Sample
input:bill:300,tips:10,Share:3,Sample output:Total bill:330.0,People per
share:110.0
Input format:
Test Case-1
Sampleinput:-
bill:300,
tips:10,
Share:3,
Sample output:-
Total bill:330.0,
People per share:110.0
Test-case-2
Sample Input:-
bill: 500
tips: 15,Share: 4,
Expected Output:
Total bill: 575.0
People per share: 143.75
Emma is planning a movie night with her friends and decides to order a
pizza for the group. She opens a pizza ordering app, and the options
pop up: she can choose between a small, medium, or large pizza. Since
they’re a big group, Emma selects the **large size**. She’s also
prompted with add-on options for toppings: **pepperoni** and extra
cheese
The first line contains a single character representing the size of the
pizza:
S for small, M for medium, or L for large.
Test case-1
Sample Input:
What size pizza do you want? S, M, or L: m
Do you want pepperoni on your pizza? Y or N: y
Do you want extra cheese? Y or N: n
Sample Output:
Your final bill is $23.
Test Case 2:
Input:
4.
Calculate the BMI for a person weighing 80 kg and 5.5 feet tall.
Determine their weight classification based on the result.
weight: 80
height: 5.5 Underweight
Input Format:
Test-case 1
Sample input:-
Weight: 80 kg
Height: 5.5 feet
Sample output:-
BMI: 28.46
Weight Classification: Overweight
Test-case 2
Sample input:-
Weight: 55 kg
Height: 5.2 feet
Sample output:-
BMI: 22.23
Weight Classification: Normal weight
Test-case 3
Sample input:-
Weight: 70 kg
Height: 5.9 feet
Sample output:-
BMI: 23.39
Weight Classification: Normal weight
Test-case 4
Sample input:-
Weight: 95 kg
Height: 6.0 feet
Sample output:-
BMI: 30.04
Weight Classification: Obese
Test-case 5:-
Sample input:-
Weight: 50 kg
Height: 5.3 feet
Sample output:-
BMI: 18.71
Weight Classification: Normal weight
5.
Before Liam pays, the attendant asks if he wants a photo taken during
the ride for an additional **$3**.
Liam decides to go for the photo option to capture the thrill of the ride.
Now, he wonders what his total bill will be after all the charges.
Question:
Using the pricing rules provided in the story, calculate Liam's total bill if
he is **15 years old** and chooses to add a photo to his rollercoaster
ride experience. What is the final amount he needs to pay?
Input Format:-
Test Case 1
Sample Input:-
Height: 135 cm
Age: 15
Wants photo: y
Sample Output:-
Final bill: 10 dollars
Test Case 2
Sample Input:-
Height: 135 cm
Age: 10
Wants photo: y
Sample Output:-
Final bill: 8 dollars
Test Case 3
Sample Input:-
Height: 135 cm
Age: 20
Wants photo: n
Sample Output:-
Final bill: 12 dollars
Input format:
The first line contains a single integer n (1 ≤ n ≤ 100), which represents
the number of Fibonacci numbers to printed .
Sample Input: 3
Sample Output: 011
Sample Input: 4
Sample Output: 0112
Sample Input: 6
Sample Output: 011234
Sample Input: 7
Sample Output: 0112345
Sample Input: 8
Sample Output: 01123456
3.
The first line contains a single string s, which can be a combination of
lowercase or uppercase alphabets. The length of the string s will be
between 1 and 100 characters.
Sample input: 1 to 10
Sample Output: 25
Sample input: 1 to 20
Sample Output: 100
Sample input: 1 to 15
Sample Output: 64
Sample input:1 to 5
Sample Output: 9
Sample input: 1 to 1
Sample Output: 1
"
"Write a Python program that iterates through numbers from 1 to 50. The
program should:
The first line contains a string that specifies the range, in the form:
""Range from X to Y"", where X and Y are integers representing the start
and end of the range (1 ≤ X ≤ Y ≤ 100).
Input: 5
Expected Output: 120
Input: 0
Expected Output: 1
Input: 7
Expected Output: 5040
Input: 3
Expected Output: 6
Input: 10
Expected Output: 3628800"
Ask input from user .Find the uppercase letter inside string using
predefined function.
"Input format:
The first line contains a single string s, which may include both
lowercase and uppercase alphabets. The string will have a length
between 1 and 100 characters.
Input: ""HelloWorld""
Expected Output: ['H', 'W']
Input: ""PythonProgramming""
Expected Output: ['P', 'P']
Input: ""OpenAI""
Expected Output: ['O', 'A', 'I']
Input: ""findUpperCASEletters""
Expected Output: ['U', 'C', 'A', 'S', 'E']
Input: ""nocaps""
Expected Output: []"
Write a Python program that takes an integer input from user.count the
number of odd number.
"Input format:
Input: 10
Expected Output: 5
(Odd numbers: 1, 3, 5, 7, 9)
Input: 15
Expected Output: 8
(Odd numbers: 1, 3, 5, 7, 9, 11, 13, 15)
Input: 1
Expected Output: 1
(Odd number: 1)
Input: 20
Expected Output: 10
(Odd numbers: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19)
Input: 0
Expected Output: 0
(No odd numbers in range)"
Input: An integer n.
Output: Print ""Even"" if n is even, otherwise ""Odd"".
Test Cases:
"
"Write a program that calculates the sum of the digits of a given number.
Input: An integer n.
Output: Print the sum of the digits of n.
Test Cases:
# Input
n = int(input(""Enter an integer: ""))
sum_of_digits = 0
Input: An integer n.
Output: Print numbers from 1 to n, excluding multiples of 3.
Input: 10 → Output: 1 2 4 5 7 8 10
Input: 6 → Output: 1 2 4 5
Input: 15 → Output: 1 2 4 5 7 8 10 11 13 14
Input: 3 → Output: 1 2
Input: 1 → Output: 1
"
"Write a program to print the first n terms of the Fibonacci series.
Input: An integer n.
Output: Print the first n numbers in the Fibonacci series.
Test Cases:
Input: 1 → Output: 0
Input: 5 → Output: 0 1 1 2 3
Input: 7 → Output: 0 1 1 2 3 5 8
Input: 10 → Output: 0 1 1 2 3 5 8 13 21 34
Input: 0 → Output: No output
# Input
n = int(input(""Enter the number of terms: ""))
a, b = 0, 1
Test Cases:
Input: 0 → Output: 1
Input: 3 → Output: 6
Input: 5 → Output: 120
Input: 7 → Output: 5040
Input: 10 → Output: 3628800
# Input
n = int(input(""Enter a positive integer: ""))
result = 1
# Calculate factorial
if n == 0:
result = 1
else:
for i in range(1, n + 1):
result *= i
print(""Factorial:"", result)
"
" Program to Calculate the Product of Digits of a Number
Problem: Given an integer n, calculate the product of its digits.
Input: An integer n.
Output: Print the product of the digits of n.
Input: An integer n.
Output: Print ""Perfect Number"" if n is a perfect number; otherwise, print
""Not a Perfect Number"".
n = int(input(""Enter an integer: ""))
sum_of_divisors = 0
if sum_of_divisors == n:
print(""Perfect Number"")
else:
print(""Not a Perfect Number"")
Test Cases:
Input: An integer n.
Output: Print the sum of the squares of the digits of n.
Test Cases:
Input: 12 → Output: 5
Input: 0 → Output: 0
Input: 99 → Output: 162"
Input: An integer n.
Output: Print ""Prime"" if n is a prime number, otherwise ""Not Prime"".
Test Cases:
# Input
n = int(input(""Enter an integer: ""))
is_prime = True
if is_prime:
print(""Prime"")
else:
print(""Not Prime"")
"
"Program to Print the Sum of All Even Numbers up to n
Problem: Given an integer n, print the sum of all even numbers from 1 to
n.
Input: An integer n.
Output: Print the sum of all even numbers from 1 to n.
Input: 10 → Output: 30
Input: 5 → Output: 6
Input: 12 → Output: 42
Input: 20 → Output: 110
Input: 1 → Output: 0"
"Program to Find the Average of Positive Integers
Problem: Given a series of integers, find the average of all positive
integers. Stop the input when a negative integer is entered.
count = 0
sum_positive = 0
while True:
num = int(input(""Enter an integer: ""))
if num < 0:
break
sum_positive += num
count += 1
if count > 0:
average = sum_positive / count
print(""Average of positive integers:"", average)
else:
print(""No positive integers entered"")
Test Cases:
Test Cases:
# Input
n = int(input(""Enter a positive integer: ""))
num_str = str(n)
num_len = len(num_str)
sum_of_powers = 0
Test Cases:
Input: 1 → Output: 1
Input: 2 → Output: 5
Input: 3 → Output: 14
Input: 5 → Output: 55
Input: 10 → Output: 385
# Input
n = int(input(""Enter a positive integer: ""))
sum_of_squares = 0
Input: An integer n.
Output: Print the count of digits in n.
if n == 0:
count = 1
else:
while n != 0:
count += 1
n //= 10
Input: An integer n.
Output: Print ""Positive"", ""Negative"", or ""Zero"" based on the value of
n.
if n > 0:
print(""Positive"")
elif n < 0:
print(""Negative"")
else:
print(""Zero"")
Test Cases:
Input: 5
Output: Positive
Input: -3
Output: Negative
Input: 0
Output: Zero
Input: 100
Output: Positive
Input: -25
Output: Negative"