Starting from:

$30

Lab Assignment no: 1 String

Course Title: Programming Language II
Course Code: CSE 111
Lab Assignment no: 1
String
1.From a given string, print the string in all uppercase if the number of uppercase
letters is more than lowercase letters. Otherwise, if lowercase is greater or equal
to uppercase letters, print all lowercase. The inputs will contain letters (A-Z, a-z)
only.
Sample
Input
HOusE
ApplE
BaNaNa
Sample
Output
HOUSE
apple
banana
2.Given a string, print whether it is a number, word or mixed with digit andletters.
If all the characters are numeric values, print NUMBER. If they are all letters,
print WORD. If it is mixed, print MIXED.
Sample
Input
213213
jhg231j213
Hello
Sample
Output
NUMBER
MIXED
WORD
3.In a given string, there will be two uppercase letters in between some lowercase
letters. Print the substring from the first uppercase letter to the last uppercase
letter excluding them. If there are no letters in between them, print the word
BLANK. It is guaranteed that there will be only two uppercase letters in the
string.
Sample Input baNgladEsh coDIng
Sample
Output glad
BLANK
4.Create a string from two given strings by concatenating common characters of
the given strings.
Sample Input
harry, hermione
dean, tom
Sample Output
hrrhr
Nothing in common.
5. Again, you have lost your USIS password!! You went to the registrar office
and requested for a new password. This time, you need to follow some rules to
set your password. Otherwise, they won't change it. The rules are
At least one lowercase letter
At least one uppercase letter
At least one digit (0-9)
At least one special character (_ , $ , #, @)
Your task is to find whether a given password follows all those rules. If it breaks
any rule, you have to print Lowercase Missing, Uppercase Missing, Digit Missing
or Special Missing respective to the missing case. For more than one rule break,
print all the rules that were broken (order doesn't matter). If the password is ok,
print OK.
Sample Input
ohMyBR@CU
ohmybracu
OhMyBR@CU20
Sample Output
Digit missing
Uppercase character missing, Digit missing, Special character missing
OK
List
1. Write a python program which prints the frequency of the numbers that were given as
input by the user. Stop taking input when you find the string “STOP”. Do not print
the frequency of numbers that were not given as input.
Sample Input
10
20
20
30
10
50
90
STOP
Sample Output 10 - 2 times
20 - 2 times
30 - 1 times
50 - 1 times
90 - 1 times
2. Write a python program that calculates the sum of N given lists and prints the highest sum
and its respective list. Input starts with N and followed by N lists.
Sample Input 4
1 2 3
4 5 6
10 11 12
7 8 9
Sample Output 33
[10, 11, 12]
3. Let there are N numbers in a list and that list is said to be a UB
Jumper if the absolute values of the difference between the
successive elements take on all the values 1 through N − 1. For
example, 2 1 4 6 10 is a UB Jumper because the absolute
differences between them are 1 3 2 4 which is all numbers from 1 to
(5 - 1) or 4. Write a python program that takes a number sequence as input
and prints whether it is a UB Jumper or Not UB Jumper. Input will stop after
getting “STOP” as input. (Number order or absolute difference order doesn’t follow
any sequence.)
Sample Input
1 4 2 3
2 1 4 6 10
1 4 2 -1 6
STOP
Sample Output
UB Jumper
UB Jumper
Not UB Jumper
4. BRACU has n students who are regular competitive programmers. According
to the ACM ICPC rules, each person can participate in the regional championship
at most 5 times.
The head of the BRACU ACM Chapter is recently gathering teams to participate
in this championship. Each team must consist of exactly three people, at that, any
person cannot be a member of two or more teams. What maximum number of
teams can the head make if he wants each team to participate in the world
championship with the same members at least k times?
The first line of input contains two integers, n and k. The next line contains n
integers: y1,y2, ...,yn (0≤ yi≤ 5), where yi shows the number of times the i-thperson
participated in the ACM ICPC Regional.
Write a python program that prints how many teams can be formed according to
the above problem statement.
Sample Input 1
5 2
0 4 5 1 0
Sample Input 2
Sample Output 1
6 4
0 1 2 3 4 5
Sample Input 3
6 5
0 0 0 0 0 0
1
Sample Output 2 0
Sample Output 3 2
Dictionary & Tuple
1. Write a Python program to combine two dictionaries into one by adding values for
common keys. Input contains two comma separated dictionaries. Print the new
dictionary and create a tuple which contains unique values in sorted order.
Sample Input
a: 100, b: 100, c: 200, d: 300
a: 300, b: 200, d: 400, e: 200
Sample Output
{'a': 400, 'b': 300, 'c': 200,'d': 700, 'e': 200}
Values: (200, 300, 400, 700)
2. Write a python program which prints the frequency of the numbers that were given as
input by the user. Stop taking input when you find the string “STOP”.Do not print
the frequency of numbers that were not given as input. Use a dictionary to solve the
problem
Sample Input 10
20
20
30
10
50
90
STOP
Sample Output 10 - 2 times
20 - 2 times
30 - 1 times 50 - 1 times
90 - 1 times
3. Write python code to invert a dictionary. It should print a dictionary where the keys are
values from the input dictionary and the values are lists of keys from the input
dictionary having the same value. Make sure the program handles multiple same
values.
Sample Input
key1 : value1, key2 : value2, key3 : value1
Sample Output
{"value1" : ["key1", "key3"], "value2" :
["key2"]}
4. On some basic cell phones, text messages can be sent using the numeric keypad.
Because each key has multiple letters associated with it, multiple key presses are
needed for most letters. Pressing the number once generates the first character listed
for that key. Pressing the number 2, 3, 4 or 5 times generates the second, third, fourth
or fifth character.
Key Symbols
1 .,?!:
2 ABC
3 DEF
4 GHI
5 JKL
6 MNO
7 PQRS
8 TUV
9 WXYZ
0 Space
Write a program that displays the key presses needed for a message entered by the user.
Construct a dictionary that maps from each letter or symbol to the key presses needed to
generate it. Then use the dictionary to create and display the presses needed for the user’s
message.
Sample Input Hello, World!
Sample Output
4433555555666110966677755531111
Function
1. You are one of the gym instructors at AmiKenoMota. You decide to provide a
customized diet and exercise plans based on the BMI of an individual. You
measure the weight in kilograms and height in meters and calculate the BMI
before a plan can be decided. Write a BMI function that takes in two values,
weight in kg and height in cm and print the score along with the condition. (Make
sure to convert cm into m before calculation)
BMI(height, weight)
������ = ����/��2
Based on the BMI score return the following output.
● < 18.5- Underweight
● 18.5 - 24.9 - Normal
● 25 -30 - Overweight
● > 30 – Obese
Sample Input (175, 96)
(152, 48)
Sample Output
Score is 31.3. You are Obese Score is 20.8. You are
Normal
2. Write a function which will take 3 arguments minimum, maximum and divisor.
You have to find all the numbers that are divisible by the divisor where minimum
value is inclusive and maximum value is exclusive. Add all the numbers and
return the value.
Sample Input (0, 10, 2)
(3, 16, 3)
Sample Output 20
45
3. You want to order Burger from Chillox through the FoodPanda App. You have to
calculate the total price. Write a function which will take the name of the burger
and place(Mohakhali/Outside of Mohakhali) as input. Use default argument
technique for taking place input.
Menu Price(T
k)
BBQ Chicken Cheese Burger
250
Beef Burger 170
Naga Drums 200
Hint: Total Price = meal_cost + delivery_charge +
tax Note that:
● If your home is in Mohakhali area then your delivery charge is 40
taka else 60 taka
● Your tax rate is 8% of your meal.
Sample Input
(‘Beef Burger’, ‘Dhanmondi’) (‘Beef Burger’)
Sample Output 243.6
223.6
4. A company named Sheba.xyz has recently moved from their old domain to
a new domain. However, a lot of the company email addresses are still using
the old one. Write a function in python that replaces this old domain with the
new
one in any outdated email addresses. Keep same if the email address contains
the new domain. (Do not use builtin replace function)
Firstly, define a “replace_domain” function which accepts three
parameters *The email address to be checked
*The new domain
* The old domain (Use Default argument technique to handle this)
Sample Input
(‘alice@kaaj.com’, ‘sheba.xyz’, ‘kaaj.com’)
(‘bob@sheba.xyz’, ‘sheba.xyz’)
Sample Output
Changed: alice@sheba.xyz Unchanged: bob@sheba.xyz
5. Write a programwhich checks whether a given string is a palindrome or not.
Note: A palindrome is a word, phrase, or sequence that reads the same backward
as forward. For palindrome, any spaces in middle are not considered and should
be trimmed.
Sample Input ‘madam’
‘hello’
‘nurses run’
Sample Output Palindrome
Not a palindrome Palindrome
6. You are a class teacher at a kindergarten school. As a task, you asked your
students to write a paragraph. Unfortunately, you notice that most of the students
did not use capital letters correctly. Your task is to write a function which takes a
string as its only parameter and returns a new copy of the string that has been
correctly capitalized. Your function should:
● Capitalize the first letter in the string
● Capitalize the first letter after a full-stop, exclamation mark or questionmark
● Capitalize the word “i” if it is in lowercase.
Summary: You have to write a function that reads a string from the user
and capitalizes. The string is then returned and displayed.
Sample Input
('my favourite animal is a dog. a dog has sharp teeth so that it can eat flesh very easily.
do you know my pet dog’s name? i love my pet very much.')
Sample Output
My favourite animal is a dog. A dog has sharp teeth so that it can eat flesh very easily. Do
you know my pet dog’s name? I love my pet very much. 

More products