This Study Resource Was: or or
This Study Resource Was: or or
#Task 1
def fraction(x,y):
if (y==0 or x==0):
print("0")
else:
return x/y-x//y
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
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
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
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)
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
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
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))
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)