BCSG 1001 - practice sheet programming Questions
1. Question: Shilpa Secret Code
In the sunlit city of Konark, Shilpa, a talented young cryptographer, is on a mission to
create the perfect encryption algorithm. She envisions a system where the characters in
a message can be securely transformed based on their positions, ensuring that only
those who know the secret can decipher it.
Shilpa’s encryption system is unique: for every string s, she modifies its characters
based on their positions. If a character is in an odd position, its ASCII value is
decreased by 2. If a character is in an even position, its ASCII value is increased by 2.
This ingenious approach guarantees an encrypted message that looks like gibberish to
outsiders but can be decoded by those in the know.
Shilpa’s task is to write a Python program that performs this custom encryption on any
given string s. Can you help Shilpa build her dream encryption algorithm? Give it a shot!
Input Format: A string s consisting of English alphabets, both uppercase and
lowercase.
Output Format: Return the encrypted string after applying the custom encryption rules.
Example
Input Hello
Output Fgjnm
Explanation
For characters at odd positions, the ASCII value of the character is decreased by 2. For
characters at even positions, the ASCII value of the character is increased by 2
2. Question: Priya Text Transformation Adventure
In the bustling city of Noida, Priya, an enthusiastic young coder, has a quirky obsession
with text manipulation. She believes that by alternating the case of characters in a
string, she can uncover hidden patterns and bring a new aesthetic to her messages.
Priya's latest challenge is to write a Python program that alternates the case of
characters in any given string, starting with uppercase for the first character. This playful
approach to text will transform ordinary sentences into something visually engaging and
dynamic.
Priya is excited to see the outcome of her experiment. Ready to join Priya in this text
transformation adventure? Let's dive into the code and see the magic unfold!
Input Format: A string s containing alphabetic characters and spaces.
Output Format: The string with alternating case.
Example
Input hello world
Output HeLlO WoRlD
Explanation
Characters alternate between uppercase and lowercase.
3. Question : Divisible or Not
You Younger sibling asks you weather a number is divisible by both 5 and 7 both daily.
Getting irritated with this behaviour you want to give him a toy which can do so. Develop
the Program for this toy.
Program takes a number as input and prints "DIV" if it is divisible by both 5 AND 7,
otherwise print’s "ND".
Example
Input 35
Output DIV
Input 42
Output ND
4. Question
Roshan is playing a game with his younger sibling that his sibling speaks a word and
Roshan spells that word in reverse. Roshan’s friend watching this, think of developing a
program to check weather Roshan is spelling reverse of a word correctly or not. You
being Roshan’s friend try developing this for the process.
Example 1
Input 1234abcd
Output dcba4321
Example 2
Input hello
Output olleh
5. Question Count of Alphabet
You are developing a program to display the count of the first alphabet of user’s names.
Your program should prompt the user to enter their name and then display a message
containing how many times has the alphabet occurred. How would you implement this
functionality in Python?
Example
Input John
Output 1
Input kruskal
Output 2
Explanation
6. Question Even Odd Game
Your friend gave you a number and asked you to find the difference between odd
placed and even placed digits, even - odd. If the difference is odd then he told you to
say true, else say false.
Write a code to demonstrate the above scenario using a function. Take a number as
input and pass it to a function and print true or false.
let the input be 1010.
Odd places digit sum is 1+1=2.
Even places sum = 0+0=0.
The difference between even place - odd place =-2 so output should be false
Example
Input 1010
Output false
Input 3613
Output true
7. Question Cart Total Price and tax
A customer adds his multiple products in the cart. You as the owner of that company
need to show the total price of cart items and the tax separately based on below
condition
If total is less than 1000 the tax to be colledcted is 10%.
If the total is more than 999 and less than 10,000 the tax to be collected is 15%.
If the total is more than 9,999 the tax to be collected is 20%, plus 2% extra
purchase tax over
the bill generated.
Convert above scenario into a program and display the bill in format shown below.
total_amount tax_amount Bill_amount
we provide two inputs, in a string format as "2000 2".
2000 is the price and
2 is the number of quantities purchased.
Total is 2000 * 2 = 4000
4000 is >999 but less than 10,000
Tax is 15% - 600
Output :
4000 600 4600
Note: If the quantity is 0, you should display the output as shown below
000
Example
Input "350 3"
Output 1050 157.5 1207.5
Input "5000 5"
Output 25000 5600 30600
Explanation : 25000 + 5000 = 30000 (on this amount extra tax of 2% is taken, which
makes total tax as 5600 ) = 30600
8. Code Name
A coach wants to code the name of the player which has the last alphabet of first name
and first alphabet of last name in capital letters. Write a function in python to generate
this code name.
Let's say the name of the player is Sachin Tendulkar then his codename is
"S.Tendulkar".
Example
Input
Sachin Tendulkar
Output
S.Tendulkar
Input
Rahul Dravid
Output
R.Dravid
9. Question Aryan Rotation Revelation
In Dubai, the Emirate of UAE, known for its iconic skyline and innovative spirit, resides
Aryan—a talented programmer with an unquenchable thirst for solving intricate
problems. One breezy afternoon, Aryan stumbles upon an intriguing challenge while
working on his latest project. The task involves rotating a list of integers by a specified
number of steps, an operation that has far-reaching applications in data manipulation
and algorithm design.
Aryan task is to develop a Python program that takes a list of integers nums and an
integer k, and rotates the list to the right by k steps. This seemingly simple operation
requires a thoughtful approach to ensure efficiency and accuracy.
With the vibrant city of Dubai as his backdrop, Aryan delves into his code, determined to
find an optimal solution. He knows that rotating the list involves rearranging elements in
such a way that the last k elements move to the front, while the rest shift accordingly.
Join Aryan on his captivating journey as he navigates through the realms of Python
programming to unveil the elegance of list rotations. Let us embark on this intellectual
adventure and witness the magic of code in transforming data.
Input Format: A list of integers nums and an integer k representing the number of
rotations (space separated).
Output Format: The modified list after rotation.
Example
Input [1,2,3,4,5,6,7] 3
Output [5,6,7,1,2,3,4]
Explanation Rotate the list to the right by k steps, means, Rotating the list by 3 steps
moves the last three elements to the front.
Input [-1,-100,3,99] 2
Output [3,99,-1,-100]
Explanation Rotating the list by 2 steps moves the last two elements to the front.
10.Twisted Prime Numbers
To identify a twisted prime, you need to confirm whether a number is prime, then
reverse the digits, and check if the reversed number is also prime.
Write a Python Function to check if a given number is a twisted prime.
Input: Take an Integer, N
Output:
If it's a Twisted Prime, print N is a Twisted Prime
else print N is not a Twisted Prime
Example
Input:
97
Output
97 is a Twisted
Prime
Explanation 97 and 79 both are Prime
11. Fahrenheit to Celsius
Your are given three inputs
● Start Fahrenheit value
● End Fahrenheit value
● Step size
You need to convert all fahrenheit values from start to end with the gap of step size, into
their corresponding Celcius values and print the table as,
Fahrenheit_value equivalent_celsius_value
Input
29
221
55
Output
29 -1
84 28
139 59
194 90
12. Alien String
You are given a string as input. For this string your task is to convert the string into an
unreadable format by replacing every character in the string by the next character in the
string.
Note - next character for z is a.
If a word is in capital in the string, corresponding conversion should be in capital
only.
T h i s i s s a m p l e
U i j t j t t b n q m f
Sample input:
This is sample
Sample output:
Uijt jt tbnqmf
13. Replace Duplicates
A student in his early years of learning decides some day to convert the sentence given
to him into a string which has -(minus sign) for all repeating characters in that string.
Can you help this student to automate the process for sentences having a larger count
of words.
Input:
A sentence
Output
Same sentence with –(dash/minus) sign replacing all repeating occurrences of
characters without spaces.
Example:
Input
This is a good long week
Output:
This--ago-dl-n-we-k
14. Replace Duplicates
Three friends Bheem, Kalia and Jerry were playing a game where Bheem was speaking
a word and, Kalia was counting vowels and Jerry was counting consonants. After that
Bheem was collecting counts of vowels and consonant and then calculating the
difference of vowels and consonants (vowels - consonants).
If the difference was zero, he said “perfect word” and Bheem won
If difference was positive, he said “positive word” and Kalia won
If the difference was negative, he said “negative word” and Jerry won.
Can you write down a program for above scenario, where input is the word spoken by
Bheem. And output shows the word is perfect, negative or positive and displays who
won the game.
Example 1:
Input:
abba
Output
perfect word Bheem
Example 2:
Input
are
Output:
positive word Kalia