-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prateek Kumar SINGH
committed
Jul 25, 2018
1 parent
8d6c1d4
commit 0733049
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
print("x = ",x) | ||
print("y = ",y) | ||
|
||
arr = [1,2,3,4,5,6] | ||
print(arr.__iter__()) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |