File tree Expand file tree Collapse file tree 10 files changed +767
-0
lines changed
Expand file tree Collapse file tree 10 files changed +767
-0
lines changed Original file line number Diff line number Diff line change 1+ def div_frac (numerator , denominator ):
2+ """
3+ Given two numbers as input, this function divide one
4+ number by another and returns the the fraction part of
5+ the result.
6+
7+ Exception: if the denominator is 0 then it returns 0.
8+ """
9+ if denominator == 0 :
10+ return 0
11+ else :
12+ result = (numerator / denominator ) - (numerator // denominator )
13+ if result == 0.0 :
14+ return 0
15+ else :
16+ return result
17+
18+
19+ print (div_frac (5 , 2 ))
20+ print (div_frac (5 , 0 ))
21+ print (div_frac (0 , 5 ))
22+
23+ # print(div_frac.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def BMI_Calc (height , weight ):
2+ """
3+ Given height and weight as input, this function
4+ calculate the BMI of a person with the following
5+ formula:
6+ BMI = Kg / 𝑚^2
7+ Then it returns the BMI and the following comment
8+ based on BMI score:
9+ * < 18.5 - Underweight
10+ * 18.5 - 24.9 - Normal
11+ * 25 - 30 - Overweight
12+ * > 30 - Obese
13+ """
14+ height = height / 100 # Converting cm to meter
15+ BMI = weight / height ** 2
16+
17+ if BMI < 18.5 :
18+ comment = "Underweight"
19+ elif BMI >= 18.5 and BMI <= 24.9 :
20+ comment = "Normal"
21+ elif BMI >= 25 and BMI <= 30 :
22+ comment = "Overweight"
23+ elif BMI > 30 :
24+ comment = "Obese"
25+
26+ return f"Score is { BMI :.1f} . You are { comment } "
27+
28+
29+ print (BMI_Calc (175 , 96 ))
30+ print (BMI_Calc (152 , 48 ))
31+
32+ # height = int(input())
33+ # weight = int(input())
34+ # print(BMI_Calc(height, weight))
35+
36+ # print(BMI_Calc.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def div_sum (min , max , div ):
2+ """
3+ This function takes 3 number maximum, minimum and divisor
4+ as input. Then it finds all the number divisible by the
5+ divisor between minimum and maximum value. Then it returns
6+ the sum of these number.
7+ """
8+ if div != 0 :
9+
10+ # Without using sum()
11+ # Sum = 0
12+ # for num in range(min, max):
13+ # if num % div == 0:
14+ # Sum += num
15+ # return Sum
16+
17+ return sum (num for num in range (min , max ) if num % div == 0 )
18+
19+ else :
20+ return "Divisor cannot be 0."
21+
22+
23+ print (div_sum (0 , 10 , 2 ))
24+ print (div_sum (3 , 16 , 3 ))
25+ print (div_sum (1 , 15 , 0 ))
26+
27+
28+ # minimum = int(input("Minimum: "))
29+ # maximum = int(input("Maximum: "))
30+ # divisor = int(input("Divisor: "))
31+ # print(div_sum(minimum, maximum, divisor))
32+
33+ # print(div_sum.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def foodpanda (food , location = "Mohakhali" ):
2+ """
3+ Given food name and location, this function calculates
4+ the total price for the food order and returns the
5+ total price.
6+ """
7+ if location != "Mohakhali" :
8+ delivery_charge = 60
9+ else :
10+ delivery_charge = 40
11+
12+ if food == "BBQ Chicken Chesse Burger" :
13+ meal_cost = 250
14+ elif food == "Beef Burger" :
15+ meal_cost = 170
16+ elif food == "Naga Drums" :
17+ meal_cost = 200
18+ else :
19+ return "The food is not on the Menu."
20+
21+ tax = meal_cost * (8 / 100 )
22+
23+ Total_Price = meal_cost + delivery_charge + tax
24+ return Total_Price
25+
26+
27+ print (foodpanda ("Beef Burger" , "Dhanmondi" ))
28+ print (foodpanda ("Beef Burger" ))
29+
30+ # food = input()
31+ # location = input()
32+
33+ # if location != "":
34+ # print(foodpanda(food, location))
35+ # else:
36+ # print(foodpanda(food))
37+
38+ # print(foodpanda.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def replace_domain (email , domain , old_domain = "kaaj.com" ):
2+ """
3+ This function takes email, domain and old domain
4+ as 3 input. If email contains the old domain then
5+ it changes it to the new domain. Then it returns the
6+ email with a comment regarding wheater the email has been
7+ changed or not.
8+ """
9+ new_email = ""
10+ index = - 1
11+ for char in range (len (email )):
12+ if email [char ] == "@" :
13+ index = char
14+ break
15+
16+ if index == - 1 :
17+ return "Incorrect E-Mail Adress!"
18+
19+ new_email = email [: index + 1 ]
20+
21+ if old_domain in email :
22+ new_email += domain
23+ comment = "Changed"
24+ else :
25+ new_email += domain
26+ comment = "Unchanged"
27+
28+ return f"{ comment } : { new_email } "
29+
30+
31+ print (replace_domain ("alice@kaaj.com" , "sheba.xyz" , "kaaj.com" ))
32+ print (replace_domain ("bob@sheba.xyz" , "sheba.xyz" ))
33+ print (replace_domain ("bobsheba.xyz" , "sheba.xyz" ))
34+
35+ # print(replace_domain.__doc__) # Acess Docstring.
Original file line number Diff line number Diff line change 1+ def vowel (string ):
2+ """
3+ Given a string, this function search for any vowels in the given string
4+ and returns the founded vowels and the vowel count as output. If no
5+ vowel found, it returns "No vowels in the name".
6+ """
7+ vowel = "aeiouAEIOU"
8+ vowel_in , total = "" , 0
9+
10+ for char in string :
11+ if char in vowel :
12+ vowel_in += char + ", "
13+ total += 1
14+
15+ if total == 0 :
16+ return "No vowels in the name"
17+ else :
18+ return f"Vowels: { vowel_in [:- 2 ]} . Total number of vowels: { total } "
19+
20+
21+ print (vowel ("Steve Jobs" ))
22+ print (vowel ("XYZ" ))
23+ print (vowel ("Anime" ))
24+ print (vowel ("AeIoU" ))
25+
26+ # print(vowel.__doc__) # Acess Docstring.
Original file line number Diff line number Diff line change 1+ def ispalindrome (word ):
2+ """
3+ Given a string as input, this function checks wheater
4+ the string is a palindrome or not. If yes, it prints
5+ "Palindrome" otherwise "Not a palindrome".
6+ """
7+ string = ""
8+ for char in word :
9+ if char != " " :
10+ string += char
11+
12+ if string == string [::- 1 ]:
13+ print ("Palindrome" )
14+ else :
15+ print ("Not a palindrome" )
16+
17+
18+ word = input ().lower ()
19+ ispalindrome (word )
20+
21+ # print(ispalindrome.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def day_to_year (day ):
2+ """
3+ Given number of days as input, this function convert and returns the
4+ days into years, month and remaining days.
5+ """
6+ year = day // 365
7+ day = day % (year * 365 )
8+ month = day // 30
9+ day = day % (month * 30 )
10+
11+ return f"{ year } years, { month } months and { day } days"
12+
13+
14+ print (day_to_year (4320 ))
15+ print (day_to_year (4000 ))
16+
17+ # print(day_to_year.__doc__) # Access Docstring
Original file line number Diff line number Diff line change 1+ def capitalize (string ):
2+ """
3+ Given a string with incorrect caplitalization, this
4+ function correctly capitalize the string and then
5+ returns it.
6+ """
7+ if string != "" :
8+ if string [0 ] >= chr (97 ) and string [0 ] <= chr (122 ):
9+ capitalized_str = chr (ord (string [0 ]) - 32 )
10+ else :
11+ capitalized_str = string [0 ]
12+
13+ for index in range (1 , len (string )):
14+ if (
15+ string [index - 1 ] == " "
16+ and string [index ] == "i"
17+ and string [index + 1 ] == " "
18+ ):
19+ capitalized_str += "I"
20+
21+ elif (
22+ string [index - 2 ] == "."
23+ or string [index - 2 ] == "!"
24+ or string [index - 2 ] == "?"
25+ ):
26+ capitalized_str += chr (ord (string [index ]) - 32 )
27+
28+ else :
29+ capitalized_str += string [index ]
30+
31+ return capitalized_str
32+
33+ else :
34+ return "Please enter a valid string."
35+
36+
37+ print (
38+ capitalize (
39+ "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."
40+ )
41+ )
42+
43+ print (capitalize ("" ))
44+
45+ # print(capitalize.__doc__) # Access Docstring
You can’t perform that action at this time.
0 commit comments