Jovian
⭐️
Sign In
In [1]:
def compareTriplets(a, b):
    lis = []
    c1=0
    c2=0
    for i in range(len(a)):
        if a[i]>b[i]:
            c1 +=1 
        elif b[i]>a[i]:
            c2 += 1
        else:
            next
    lis.insert(0,c1)
    lis.insert(1,c2)
    return lis


a = [9,8,9]
b = [7,4,6]

compareTriplets(a,b)
Out[1]:
[3, 0]
In [2]:
def diagonalDifference(arr):
    l = len(arr[0])
    a = 0
    b = 0
    for i in range(l):
        a += arr[i][i]
    for i in range(l-1,-1,-1):
        b += arr[l-1-i][i]
    return abs(a-b)

arr=[[1,2,3],[4,5,6],[7,8,9]]
diagonalDifference(arr)
Out[2]:
0
In [3]:
for i in range(11):
    print("* "*i)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
In [5]:
def plusMinus(arr):
    p = 0
    ne = 0
    z = 0
    l=len(arr)
    for iteam in range(n):
        if arr[iteam]%2==0:
            p += 1
        if arr[iteam]%2!=0:
            ne += 1
        if arr[iteam]==0:
            z+=1
    pp = p/l
    nn = ne/l
    zz = z/l
    
    return pp,nn,zz

arr = [5,7,-3,0,-4,1]
n = len(arr)
plusMinus(arr)
Out[5]:
(0.3333333333333333, 0.6666666666666666, 0.16666666666666666)
In [ ]:
s = '07:05:45PM'
s1 = s.split(':')
s1
In [ ]:
lis = []
for i in s1[2]:
    lis.append(i)
lis
In [ ]:
out1 = []
out2 = []
int(s1)
if s1[0]<12:
    out1.inser(s1[0+=12],0)
    
elif s1[0]>
In [ ]:
s = '07:05:45PM'
for i in s:
    print(i , end=' ')

In [ ]:
s = '04:59:59AM'
hr = ''
for i in range(len(s)-8):
    hr+=s[i]

min = ''
for i in range(3,len(s)-5):
    min+=s[i]

sec = ''
for i in range(6,len(s)-2):
    sec+=s[i]

fnan = s[8]

hrout = []
i = 0
j = 1

if(int(hr[i])==0 and int(hr[j])<=9 and fnan == 'P'):
    hrout.insert(0,int(hr)+12)
elif(int(hr[i])==0 and int(hr[j])<=9 and fnan == 'A'):
    hrout.append("0{}".format(int(hr[j])))
elif(int(hr[i])!=0 and int(hr[j])<2 and fnan == 'P'):
    hrout.insert(0,int(hr)+12)
elif(int(hr[0])==1 and int(hr[1])==2 and fnan =='P'):
    hrout.insert(0,int(hr))
elif(int(hr[0])==1 and int(hr[1])==2 and fnan =='A'):
    hrout.append('00')
    
hrout1 = ''
for i in range(len(hrout)):
    hrout1 = hrout[i]
    
print("{}:{}:{}".format(hrout1,min,sec))
In [ ]:
 
In [18]:
import math
grades = [73,67,38,33,41,99]
lis = []
for i in range(len(grades)):
    if grades[i]<38 :
        lis.append(grades[i])
    else:
        r = 5-grades[i]%5
        if r<=2:
            s1 = ((math.floor(grades[i]/5))+1)*5
            lis.append((int(s1)))
        else:
            lis.append(grades[i])
print(lis)

75 40 100 [75, 67, 40, 33, 41, 100]
In [52]:
s= 2
t = 3
a = 1
b = 5
m = 1
n = 1
apples= [2]
oranges = [-2]
c1 = 0
c2 = 0
for i in range(m):
    if apples[i]>0:
        if t>=a+apples[i]>=s:
            c1+=1
for j in range(n):
    if oranges[j]<0:
        if s<=b+oranges[j]<=t:
            c2+=1
    
        
print(c1,c2)      
        
        
        
        
        
1 1
In [4]:
## Kangaroo problem
In [17]:
import time
def kangaroo(x1, v1, x2, v2):
    b1 = [] 
    a1 = []
    for i in range(1,10001):
        a1.append(x1+v1*i)
        b1.append(x2+v2*i)
    #print(a1,b1)   
    for i in range(10000):
        if a1[i]==b1[i]:
            return 'YES'
    for i in range(10000):
        if a1[i]!=b1[i]:
            return 'NO'  
        
kangaroo(0,3,4,2)
Out[17]:
'YES'
In [12]:
grades = [73,38,67,33]
one =[]
for i in range(len(grades)):
    one.append(round(grades[i]/10,0))
print(one)
out = []
for i in range(len(grades)):
    if grades[i]<=37:
        out.append(grades[i])
    elif abs(one[i]*10+5-grades[i])<3:
        out.append(int(one[i]*10+5))
    else:
        out.append(grades[i])
     
print(out)
[7.0, 4.0, 7.0, 3.0] [75, 38, 67, 33]
In [1]:
import winsound
In [4]:
freq = [37,23,76,12,87,36,87]
  
# duration is set to 100 milliseconds           
dur = 1000
flag = True 
while flag:
    u = int(input("Enter key: "))
    if u in range(1,8):
        winsound.Beep(freq[u], dur)
Enter key: 1
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-4-9b2b2e550239> in <module> 7 u = int(input("Enter key: ")) 8 if u in range(1,8): ----> 9 winsound.Beep(freq[u], dur) ValueError: frequency must be in 37 thru 32767
In [ ]:
 
In [ ]:
 
In [ ]: