Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Prateek Kumar SINGH committed Jul 25, 2018
1 parent 8d6c1d4 commit 0733049
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Python Basics/04_Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
print("x = ",x)
print("y = ",y)

arr = [1,2,3,4,5,6]
print(arr.__iter__())



29 changes: 29 additions & 0 deletions Python Basics/MiniProjects/6_Diagonal_Difference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/python3
# Given a square matrix, calculate the absolute difference between the sums of its diagonals.

import math
import os
import random
import re
import sys

# Complete the diagonalDifference function below.
def diagonalDifference(arr):
size = len(arr[0]) - 1
print('size:',size)
lrd = rld = 0
for i in range(0,size+1):
print('arr[{0}][{1}]={2}'.format(i,i,arr[i][i]))
lrd += arr[i][i]
x=size-i
print('arr[{0}][{1}]={2}'.format(i,x,arr[i][x]))
rld += arr[i][(size-i)]
print('rld',rld)
print('lrd',lrd)
return abs(lrd-rld)

arr = [[1,2,3],
[4,5,6],
[7,8,9]]

print(diagonalDifference(arr))
8 changes: 8 additions & 0 deletions Python Basics/MiniProjects/7_Staircase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def staircase(n):
for i in range(0,n):
times = n-i-1
rem = n-times
out = " "*times + '#'*rem
print(out)

staircase(8)
14 changes: 14 additions & 0 deletions Python Basics/MiniProjects/8_Time_Conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def timeConversion(s):
ampm = ''.join(list(s)[-2:])
hours, mins, secs = s.replace(ampm,'').split(':')
if int(hours) <12 and int(mins) <=59 and int(secs) <=59:
if ampm == 'PM':
hours = int(hours) + 12
elif ampm == 'AM' and int(hours)==12:
hours = 0

return '{0}:{1}:{2}'.format(str(hours).zfill(2),str(mins).zfill(2),str(secs).zfill(2))

print(timeConversion('12:45:54PM'))
print(timeConversion('01:45:54AM'))
print(timeConversion('00:45:54AM'))

0 comments on commit 0733049

Please sign in to comment.