0% found this document useful (0 votes)
36 views4 pages

This Study Resource Was: or or

The document contains 10 programming tasks that involve writing Python functions to perform various tasks such as calculating fractions, BMI, sums, replacing email domains, checking for palindromes, formatting dates, and capitalizing sentences. Each task provides sample input/output to demonstrate the function.

Uploaded by

Shamsul Rahat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

This Study Resource Was: or or

The document contains 10 programming tasks that involve writing Python functions to perform various tasks such as calculating fractions, BMI, sums, replacing email domains, checking for palindromes, formatting dates, and capitalizing sentences. Each task provides sample input/output to demonstrate the function.

Uploaded by

Shamsul Rahat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

In [1]:

#Task 1

def fraction(x,y):
if (y==0 or x==0):
print("0")
else:
return x/y-x//y

x = int((input("Enter a number: ")))


y = int((input("Enter another number: ")))
a = fraction(x,y)
print(a)

Enter a number: 17
Enter another number: 3
0.666666666666667

In [2]:
#Task 2

m
def bmi(height,weight):

er as
return weight/height

co
eH w
h = float(input("Enter the height in cm: "))
weight = float(input("Enter the weight in kg: "))

o.
height = (h/100)**2 rs e
ou urc
x = bmi(height,weight)
if (x<18.5):
print("Score is",x,"you are Underweight")
elif(x >= 18.5 and x <= 24.9):
o

print("Score is",x,"you are Normal")


aC s

elif(x >= 25 and x <= 30):


v i y re

print("Score is",x,"you are Overweight")


else:
print("Score is",x,"you are Obese")

Enter the height in cm: 175


ed d

Enter the weight in kg: 96


ar stu

Score is 31.346938775510203 you are Obese

In [1]:
sh is

#Task 3
Th

def function(minimum,maximum,divisor):
x=0
for i in range(minimum,maximum,divisor):
x=x+i

return x

minimum = int(input("Enter the minimum value: "))


maximum = int(input("Enter the maximum value: "))
divisor = int(input("Enter the value for divisor: "))
x = function(minimum,maximum,divisor)
print(x)

Enter the minimum value: 0


Enter the maximum value: 10
Enter the value for divisor: 2
20
This study source was downloaded by 100000828609975 from CourseHero.com on 07-03-2021 23:16:01 GMT -05:00
In [2]:
#Task 4
https://www.coursehero.com/file/98359501/Assignment02-pdf/
def chillox(name,place=""):
price=int()
tax=int()
charge=int()
tax=int()
if (name=="BBQ Chicken Cheese Burger"):
price=250

if (name=="Beef Burger"):
price=170

elif(name=="Naga Drums"):
price=200

if (place=="Mohakhali" or place==""):
charge=40

elif(place!="Mohakhali"):
charge=60

tax = price*(8/100)
total = price+charge+tax
return total

name = input("Enter the meal name: ")

m
place = input("Enter the place: ")

er as
x = chillox(name,place)

co
print(x)

eH w
Enter the meal name: Beef Burger

o.
Enter the place: Dhanmondi rs e
243.6
ou urc
In [6]:
#Task 5
o
aC s

def replace_domain(email,new,old=""):
v i y re

line=email.split("@")
y=line[0]+"@"+new
if old=="":
return("Unchanged",y)
ed d

else:
ar stu

return("Changed",y)

email = input("Enter the email to be changed: ")


new = input("Enter the new domain: ")
sh is

old = input("Enter the old domain: ")


print(replace_domain(email,new,old))
Th

Enter the email to be changed: [email protected]


Enter the new domain: sheba.xyz
Enter the old domain: kaaj.com
('Changed', '[email protected]')

In [11]:

#Task 6

def functn(w):

vl=['a','e','i','o','u']
st=''
count=0
for i in (range(len(inp))):
if w[i] in vl:
count+=1
This study source was downloaded by 100000828609975 from CourseHero.com on 07-03-2021 23:16:01 GMT -05:00
st+=w[i]

https://www.coursehero.com/file/98359501/Assignment02-pdf/
if count==0:
print('No vowels found')
else:
print('Vowels are:',end='')

for i in range(len(st)-1):
n=st[i]
print(n+',',end='')
print(st[-1]+'.',end='')
print('Total number of vowel',count)

inp = input()
functn(inp)

Steve Jobs
Vowels are:e,e,o.Total number of vowel 3

In [12]:
#Task 7

word = input("Enter a word or a sentence or a phrase: ")


word = word.replace(" ","")

m
p = reversed(word)

er as
co
if list(word)==list(p):

eH w
print("Palindrome")
else:

o.
print('Not a palindrome') rs e
ou urc
Enter a word or a sentence or a phrase: madam
Palindrome
o

In [13]:
aC s

#Task 8
v i y re

def format(date):
x=date//365
y=x*365
year=x
ed d

z=date-y
ar stu

a=z//30
c=a*30
month=a
b=z-c
sh is

day=b
print(year,"years,",month,"months","and",day,"days")
Th

date = int(input("Enter the number of days: "))


format(date)

Enter the number of days: 4320


11 years, 10 months and 5 days

In [14]:
#Task 9

def my_func(string):
my_list=list(string)
my_list[0]=my_list[0].upper()
for i in range(1, len(string)-1):
if string[i]=='?' or string[i]=='.' or string[i]=='!':
my_list[i+2]=string[i+2].upper()
elif string[i]==' ' and string[i+1]=='i' and string[i+2]==' ':
This study source was downloaded by 100000828609975 from CourseHero.com on 07-03-2021 23:16:01 GMT -05:00
my_list[i+1]=my_list[i+1].upper()
for i in range(0,len(my_list)):
print(my_list[i],end='')
https://www.coursehero.com/file/98359501/Assignment02-pdf/
return('')
string=input('enter your lines: ')
print(my_func(string))

enter your lines: my favorite animal is a dog


My favorite animal is a dog

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th

This study source was downloaded by 100000828609975 from CourseHero.com on 07-03-2021 23:16:01 GMT -05:00

https://www.coursehero.com/file/98359501/Assignment02-pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like