Cse1005 Sample Questions - Module-1
Cse1005 Sample Questions - Module-1
Input:
An integer 𝑁
Question 1: Sum of N Natural Numbers N (1 ≤ 𝑁 ≤ 10^6)
Problem Statement:
Write a Python program to calculate the sum of the first N natural numbers. Output:
The sum of the digits of 𝑁.
Input: an Integer N
N (1 ≤ N ≤ 1000) Test Cases:
55 Input: 9999
1+2+3+...+10=55 Output: 36
Explanation:
Input: 1 9+9+9+9=36
Output: 1
Input: 54321
Input: 20 Output: 15
Output: 210 Explanation:
5+4+3+2+1=15
Input: 100
Output: 5050 Input: 1
Output: 1
Input: 1000
1 Output: 500500
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
Question 2: Count Digits in a Number
->8+1=9
Problem Statement:
Write a program to count the number of digits in a given positive integer 𝑁.
. Input: 1
Input: Output: Yes
An integer 𝑁 Explanation:
N (1 ≤ 𝑁 ≤ 100000000000) 1^2 = 1
Output: Input: 10
The number of digits in 𝑁 Output: No
Explanation:
10^2 =100
Test Cases: -> 1+0+0=1, which is not equal to 10.
Input: 9 Input: 45
Output: 1 Output: No
Explanation:
Input: 456789 45^2 = 2025
Output: 6 2+0+2+5=9, which is not equal to 45.
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:
Question 3: Print Even Numbers in a Range
Problem Statement: Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Write a program to print all even numbers from 0 to A Output:
Input: ai Input: 13
Output: 2 Output: Yes
Explanation: The vowels in ai are a and i, so the count is 2.
Input: 4
Input: xyz Output: No
Output: 0
Explanation: There are no vowels in xyz, so the count is 0. Input: 29
Output: Yes
Input: python
Output: 1 Input: 100
Explanation: The only vowel in python is o, so the count is 1 Output: No
ABSOLUTE
DIFFERENCE IN
Shopping Cart Total Leap Year Odd and even Count PRIME NUMBER RANGE
Problem Statement: Problem Statement: Problem Statement: Problem Statement:
You need to calculate the Write a program to write a program to find total number of odd digit Take an integer and You are given two integers,
total cost of items in a print "YES" if the integer start and end, where start is
shopping cart after applying
check whether the and even digit in a given whole number(Dont strictly less than end. Your
given year is a leap consider zero as even number) is prime and "NO" if it is
a discount. First, apply the task is to compute the
not.
initial discount based on the year or not absolute value of the sum of
specified percentage. If the all integers between start
total cost after this initial and end (exclusive). In other
discount exceeds ₹100, words, you need to subtract
apply an additional discount each integer from the sum
of 10% to the total. of all integers in the range
from start+1 to end
(inclusive).
Input Format: Input Format: Input Format: Input Format: Input Format:
Output Format: Output Format: Output Format: Output Format: Output Format:
Print only the total cost Print Leap YeaR or Print the absolute difference
after discounts Not Leap YeaR Print count of odd digit and even digit YES OR NO value
Sample Input: Sample Input: Sample Input: Sample Input: Sample Input:
3 1999 65841520 9 1
50 . 0 Sample output : 10
30 . 0 Not Leap YeaR Sample output : Sample output :
25 3 NO Sample output :
20 TESTCASE - 1 4 54
INPUT TESTCASE - 1
Sample output : 2024 TESTCASE - 1 INPUT TESTCASE - 1
84 . 0 OUTPUT INPUT 88888 INPUT
Leap YeaR 88888 OUTPUT 10
TESTCASE - 1 OUTPUT NO 100
INPUT TESTCASE - 2 0 OUTPUT
4 INPUT 5 TESTCASE - 2 4995
60 1900 INPUT
40 OUTPUT TESTCASE - 2 79 TESTCASE - 2
30 Not Leap YeaR INPUT OUTPUT INPUT
20 333333 YES 200
10 TESTCASE - 3 OUTPUT 500
OUTPUT INPUT 6 TESTCASE - 3 OUTPUT
121.5 2000 0 INPUT 105150
OUTPUT 97
TESTCASE - 2 Leap YeaR TESTCASE - 3 OUTPUT TESTCASE - 3
INPUT INPUT YES INPUT
5 TESTCASE - 4 1234567 -1
100 INPUT OUTPUT TESTCASE - 4 100
50 2009 4 INPUT OUTPUT
20 OUTPUT 3 111 5050
10 Not Leap YeaR OUTPUT
5 TESTCASE - 4 NO TESTCASE - 4
15 INPUT INPUT
OUTPUT 1357924680 -50
141.5 OUTPUT 50
5 OUTPUT
TESTCASE - 3 4 50
INPUT
4
129
879
560
156
10
OUTPUT
1396.4
TESTCASE - 4
INPUT
3
190
540
632
12
OUTPUT
1078.7
MEDIUM LEVEL MEDIUM LEVEL MEDIUM LEVEL MEDIUM LEVEL MEDIUM LEVEL
first and last guy Fibonacci number TWISTED PRODUCT SPECIAL NUMBER ARMSTRONG OR NOT
Problem Statement: Problem Statement: Problem Statement: Problem Statement: Problem Statement:
write a program to Find the nth fibonacci Take two numbers and find sum of all numbers between Take an integer as input and Write a program to
them that satisfy following condition (inclusive range): print 'YES' if the number is a
sum the frst two and number of a special number. Otherwise, take a number from
last two digit of a sequence print 'NO'. the input and print
number whether or not it's an
Hint:
A special number is a
armstrong number.
number which is equal to 153 = (1*1*1)+(5*5*5)
the sum of the factorials of +(3*3*3) sample two:
its digits.
Example:
8208=> (8**4)+(2**4)+
For number = 145, the (0**4)+(8**4)=>8208
output should be 1! + 4! + 5!
= 145
Hence 145 is a special
number.
Input Format: Input Format: -> Second last digit of number is 4 Input Format:
The first line contains an The first line contains The first line contains
integer N an integer N Input Format: Input Format: an integer N
The first line contains
constrains : Two lines of input each containing a single integer. an integer N
9<N<=10^12 FIRST VALUE INDICATES START VALUE OF RANGE Output Format:
SECOND VALUE INDIACTES END VALUE OF RANGE YES OR NO
Output Format: Output Format: Output Format: TESTCASE - 1
INPUT Output Format:
print the n th position
value in fibonacci A single integer which is the product of all such numbers
sum as integer series which follow the above mentioned conditions. 143 YES OR NO
OUTPUT
Sample Input: Sample Input: Sample Input: NO Sample Input:
30
65165 5 40 TESTCASE - 2 153
Sample output : Sample output : INPUT sample output:
Sample output : 3 40 40585 YES
22 OUTPUT TESTCASE - 1
TESTCASE - 1 TESTCASE - 1 YES INPUT
TESTCASE - 1 INPUT INPUT 123
INPUT 5 10 TESTCASE - 3 OUTPUT
123456 OUTPUT 100 INPUT NO
OUTPUT 3 OUTPUT 6451
14 221 OUTPUT TESTCASE - 2
TESTCASE - 2 NO INPUT
TESTCASE - 2 INPUT TESTCASE - 2 370
INPUT 100 INPUT TESTCASE - 4 OUTPUT
123456 OUTPUT 10 INPUT YES
21892299583455516
OUTPUT 9026 200 1
14 OUTPUT OUTPUT TESTCASE - 3
TESTCASE - 3 941 YES INPUT
TESTCASE - 3 INPUT 371
INPUT 20 TESTCASE - 3 OUTPUT
123457 OUTPUT INPUT YES
OUTPUT 4181 100
15 200 TESTCASE - 4
TESTCASE - 4 OUTPUT INPUT
TESTCASE - 4 INPUT 721 152
INPUT 10 OUTPUT
875612 OUTPUT TESTCASE - 4 NO
OUTPUT 34 INPUT
18 100
1000
OUTPUT
EASY-LEVEL(I ADD EXTRA 4 QUESTIONS
FOR BACKUP) MEDIUM - LEVEL 24481
Find the Fibnocci Series of Number, 1.Check number is Armstrong or not using loop,
Input format:
Sample Input: 8
Sample Output: 01123456
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:
Reverse the String using for loop without predefined Function, 110.0
Input format:
Test Case-1
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:
Sample Output:
Your final bill is $23.
Test Case 2:
Input:
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
Input format:
The first line contains two integers, a and b (1 ≤ a ≤ b ≤ 100), separated by the Sample output:-
word "to". These integers represent a range starting from a to b. BMI: 18.71
Weight Classification: Normal weight
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
5.
The attendant informs him that the ride costs different amounts based
on age:
- $7** for ages 18 and under
- $5** for ages 12 and under
- $12** for ages 19 and older
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.
Write a Python program that iterates through numbers from 1 to 50. The Question:
program should:
Using the pricing rules provided in the story, calculate Liam's total bill
Print only the even numbers. if he is **15 years old** and chooses to add a photo to his
Skip numbers that are multiples of 5. rollercoaster ride experience. What is the final amount he needs to
Stop the loop entirely if it reaches the number 49. pay?
Input Format:-
Test Case 1
Sample Input:-
Height: 135 cm
Age: 15
Wants photo: y
The first line contains a single integer n (0 ≤ n ≤ 20), which represents the
number for which you need to calculate the factorial.
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:
The first line contains a single integer n (0 ≤ n ≤ 100), which represents the
upper limit of the range starting from 1.
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 "Prime" if n is a prime number, otherwise "Not Prime".
Write a program that checks if a given integer is even or odd. Test Cases:
Input: An integer n.
Output: Print the sum of the digits of n. 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.
Test Cases:
Input: An integer n.
Input: 123 → Output: 6 Output: Print the sum of all even numbers from 1 to n.
Input: 0 → Output: 0
Input: 456 → Output: 15 n = int(input("Enter an integer: "))
Input: 789 → Output: 24 sum_even = 0
Input: 1023 → Output: 6
for i in range(2, n + 1, 2):
# Input sum_even += i
n = int(input("Enter an integer: "))
sum_of_digits = 0 print("Sum of even numbers:", sum_even)
Test Cases:
# Calculate sum of digits
for digit in str(n): Input: 10 → Output: 30
sum_of_digits += int(digit) Input: 5 → Output: 6
Input: 12 → Output: 42
print("Sum of digits:", sum_of_digits) 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
Program to Skip Multiples of 3 Using Continue sum_positive = 0
Problem: Given an integer n, print all numbers from 1 to n, skipping multiples of 3.
while True:
Input: An integer n. num = int(input("Enter an integer: "))
Output: Print numbers from 1 to n, excluding multiples of 3. if num < 0:
break
sum_positive += num
n = int(input("Enter an integer: ")) count += 1
Input: An integer n.
Program to Calculate the Product of Digits of a Number Output: Print the count of digits in n.
Problem: Given an integer n, calculate the product of its digits.
if n == 0:
n = int(input("Enter an integer: ")) count = 1
product = 1 else:
while n != 0:
for digit in str(n): count += 1
product *= int(digit) n //= 10
Input: An integer n.
Output: Print "Perfect Number" if n is a perfect number; otherwise, print "Not a Perfect Number".
Input: An integer n.
Program to Calculate the Sum of Square of Digits Output: Print "Positive", "Negative", or "Zero" based on the value of n.
Problem: Given an integer n, calculate the sum of the squares of its digits.