Starting from:

$34.99

CSE111 Lab 2 Solution


1. Write a function which will return the fraction part after dividing a number by another. The range should be within 0 and 1. Exception: Since dividing anything by 0 results in error so if the denominator is 0, the function will return 0 instead of attempting the division.

Sample Input
(5, 2)
(5, 0)
(0, 5) Sample Output
0.5
0
0

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

3. 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


4. 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(Tk)
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


5. 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
6. Write a function which takes only your full name as input and finds the total number of vowels in that input. Output every vowel and at the end output the total number of vowels found. If your name does not contain any vowel then your function should print “No vowels in the name!”.



Sample Input
(Steve Jobs)
(XYZ)

Sample Output
Vowels: e, e, o. Total number of vowels: 3
No vowels in the name


7. Write a program which 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



8. Write a function which takes a number of days as input and prints total number of years, number of months and remaining number of days as output.


Sample Input
(4320)
(4000)

Sample Output
11 years, 10 months and 5 days
10 years, 11 months and 20 days



● Capitalize the first letter in the string
● Capitalize the first letter after a full-stop, exclamation mark or question mark
● 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