ELIZEBETH's WALK
================================================================
x,y,z,m1=int(input()),int(input()),int(input()),int(input())
time=(y*9/5)+(z*3/5)+(x*6/5)
print(int(6+time//3600),int(time//60)%60)
time=time+(z*9/5)+(y*3/5)+(x*6/5)+m1*60
print(int(6+time//3600),int(time//60)%60)
======================================================
Count Unique Words
=======================================================
from pprint import pprint
k=input()
c=0
d={}
import sys
import re
for ch in k:
if(re.match("[0-9]",ch)):
print("Invalid input")
sys.exit()
for ch in range(len(k)-1):
if(re.match("[^A-Za-z0-9]",k[ch]) and re.match("[^A-Za-z0-9]",k[ch+1]) and k[ch]!=" " and k[ch+1]!=" "):
print("Invalid input")
sys.exit()
for j in range(len(k)):
if(k[j]==" "):
temp=k[c:j]
temp=temp.lower()
for p in temp[0:len(temp)-1]:
if(re.match("[^A-Za-z]",p)):
print("Invalid input")
sys.exit()
if(re.match("[^A-Za-z]",temp[len(temp)-1])):
temp=temp[0:len(temp)-1]
c=j+1
if(temp in list(d.keys())):
d[temp]=d[temp]+1
else:
d[temp]=1
temp=k[c:]
temp=temp.lower()
for p in temp[0:len(temp)-1]:
if(re.match("[^A-Za-z]",p)):
print("Invalid input2")
sys.exit()
if(re.match("[^A-Za-z]",temp[len(temp)-1])):
temp=temp[0:len(temp)-1]
if(temp in list(d.keys())):
d[temp]=d[temp]+1
else:
d[temp]=1
pprint(d)
==================================================================
Sentiment analysis
==============================================================
B=["awful","bad","cruel","damage","evil","fear","greed","horrible","ill","jealous"]
G=["amazing","awesome","excellent","fantastic","great","incredible","outstanding","perfect","beautiful","cute"]
Bi,Bt=0,0
Gi,Gt=0,0
N=0
n=int(input())
for k in range(n):
S=input()
c=0
for ch in range(len(S)):
if(S[ch]==" "):
if(S[c:ch] in B):
Bt=Bt+1
break
elif(S[c:ch] in G):
Gt=Gt+1
break
print(format((1-(Gt/n)-(Bt/n)),"0.2f"))
print(format((Gt/n),"0.2f"))
print(format((Bt/n),"0.2f"))
=========================================================================
8 - Queen PUZZLE
========================================================================
================================================================
x,y,z,m1=int(input()),int(input()),int(input()),int(input())
time=(y*9/5)+(z*3/5)+(x*6/5)
print(int(6+time//3600),int(time//60)%60)
time=time+(z*9/5)+(y*3/5)+(x*6/5)+m1*60
print(int(6+time//3600),int(time//60)%60)
======================================================
Count Unique Words
=======================================================
from pprint import pprint
k=input()
c=0
d={}
import sys
import re
for ch in k:
if(re.match("[0-9]",ch)):
print("Invalid input")
sys.exit()
for ch in range(len(k)-1):
if(re.match("[^A-Za-z0-9]",k[ch]) and re.match("[^A-Za-z0-9]",k[ch+1]) and k[ch]!=" " and k[ch+1]!=" "):
print("Invalid input")
sys.exit()
for j in range(len(k)):
if(k[j]==" "):
temp=k[c:j]
temp=temp.lower()
for p in temp[0:len(temp)-1]:
if(re.match("[^A-Za-z]",p)):
print("Invalid input")
sys.exit()
if(re.match("[^A-Za-z]",temp[len(temp)-1])):
temp=temp[0:len(temp)-1]
c=j+1
if(temp in list(d.keys())):
d[temp]=d[temp]+1
else:
d[temp]=1
temp=k[c:]
temp=temp.lower()
for p in temp[0:len(temp)-1]:
if(re.match("[^A-Za-z]",p)):
print("Invalid input2")
sys.exit()
if(re.match("[^A-Za-z]",temp[len(temp)-1])):
temp=temp[0:len(temp)-1]
if(temp in list(d.keys())):
d[temp]=d[temp]+1
else:
d[temp]=1
pprint(d)
==================================================================
Sentiment analysis
==============================================================
B=["awful","bad","cruel","damage","evil","fear","greed","horrible","ill","jealous"]
G=["amazing","awesome","excellent","fantastic","great","incredible","outstanding","perfect","beautiful","cute"]
Bi,Bt=0,0
Gi,Gt=0,0
N=0
n=int(input())
for k in range(n):
S=input()
c=0
for ch in range(len(S)):
if(S[ch]==" "):
if(S[c:ch] in B):
Bt=Bt+1
break
elif(S[c:ch] in G):
Gt=Gt+1
break
print(format((1-(Gt/n)-(Bt/n)),"0.2f"))
print(format((Gt/n),"0.2f"))
print(format((Bt/n),"0.2f"))
=========================================================================
8 - Queen PUZZLE
========================================================================
import sys
n=int(input())
cx=n
cy=1
if(n<=0):
print("Invalid input")
sys.exit()
if(cx+1<=3):
print(cx+1)
print(cy)
if(cy-1>0):
print(cx)
print(cy-1)
if(cx-1>0):
print(cx-1)
print(cy)
if(cy+1<=3):
print(cx)
print(cy+1)
cy=2
if(cx+1<=3):
print(cx+1)
print(cy)
if(cy-1>0):
print(cx)
print(cy-1)
if(cx-1>0):
print(cx-1)
print(cy)
if(cy+1<=3):
print(cx)
print(cy+1)
cy=3
if(cx+1<=3):
print(cx+1)
print(cy)
if(cy-1>0):
print(cx)
print(cy-1)
if(cx-1>0):
print(cx-1)
print(cy)
if(cy+1<=3):
print(cx)
print(cy+1)
=====================================================================
MANGO
=====================================================================
n=int(input()) print n*6
====================================================================
GMT-to-IST
======================================================================
D,h,m=input(),int(input()),int(input())
d={"Sunday":0,"Monday":1,"Tuesday":2,"Wednesday":3,"Thursday":4,"Friday":5,"Saturday":6}
d1=-1
import sys
for j in list(d.keys()):
if(j==D):
d1=d[D]
if(d1==-1 or h>=24 or h<0 or m<0 or m>=60):
print("Invalid input")
sys.exit()
m=(m+30)
h=h+m//60+5
m=m%60
if(h>=24):
h=h-24
d1=d1+1
d1=d1%7
for p in list(d.keys()):
if(d[p]==d1):
print(p)
print(h)
print(m)
=================================================================================HISTOGRAM
============================================================================
from pprint import pprint
import re
import sys
n=input()
d={}
n=n.lower()
for ch in n:
if(re.match("[^a-z]",ch)):
print("Invalid input")
sys.exit()
for ch in n:
if(ch in list(d.keys())):
d[ch]=d[ch]+1
else:
d[ch]=1
pprint(d)
d1={}
for j in range(len(n)):
temp=[]
for p in list(d.keys()):
if(d[p]==j):
temp.append(p)
if(len(temp)>0):
temp.sort()
d1[j]=temp
pprint(d1)
=================================================================================
ARMSTRONG NUMBER
=================================================================================import sys
n=int(input())
n1=n
n2=n
d=0
if(n<0):
print("Invalid input")
sys.exit(1)
while(n>0):
d=d+1
n=n//10
arm=0
while(n1>0):
dig=n1%10
n1=n1//10
arm=arm+dig**d
if(arm==n2):
print("Yes")
else:
print("No")
=================================================================================
PLANT GRAPES
==============================================================================
l,b=int(input()),int(input()) print((int((l-6)/3)+1)*(int((b-6)/3)+1))
===============================================================================
No comments:
Post a Comment