File tree 3 files changed +137
-0
lines changed
3 files changed +137
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Cartesian Product of Two Lists."""
2
+
3
+ # Import
4
+ from itertools import product
5
+
6
+
7
+ # Cartesian Product of Two Lists
8
+ def cartesian_product (list1 , list2 ):
9
+ """Cartesian Product of Two Lists."""
10
+ for _i in list1 :
11
+ for _j in list2 :
12
+ print ((_i , _j ), end = ' ' )
13
+
14
+
15
+ # Main
16
+ if __name__ == '__main__' :
17
+ list1 = input ().split ()
18
+ list2 = input ().split ()
19
+
20
+ # Convert to ints
21
+ list1 = [int (i ) for i in list1 ]
22
+ list2 = [int (i ) for i in list2 ]
23
+
24
+ cartesian_product (list1 , list2 )
25
+
Original file line number Diff line number Diff line change
1
+ """Rangoli Model"""
2
+
3
+
4
+ # Prints a rangoli of size n
5
+ def print_rangoli (n ):
6
+ """Prints a rangoli of size n"""
7
+ # Width of the rangoli
8
+ width = 4 * n - 3
9
+
10
+ # String to be printed
11
+ string = ""
12
+
13
+ # Loop to print the rangoli
14
+ for i in range (1 , n + 1 ):
15
+ for j in range (0 , i ):
16
+ string += chr (96 + n - j )
17
+ if len (string ) < width :
18
+ string += "-"
19
+
20
+ for k in range (i - 1 , 0 , - 1 ):
21
+ string += chr (97 + n - k )
22
+ if len (string ) < width :
23
+ string += "-"
24
+
25
+ print (string .center (width , "-" ))
26
+ string = ""
27
+
28
+ for i in range (n - 1 , 0 , - 1 ):
29
+ for j in range (0 , i ):
30
+ string += chr (96 + n - j )
31
+ if len (string ) < width :
32
+ string += "-"
33
+
34
+ for k in range (i - 1 , 0 , - 1 ):
35
+ string += chr (97 + n - k )
36
+ if len (string ) < width :
37
+ string += "-"
38
+
39
+ print (string .center (width , "-" ))
40
+ string = ""
41
+
42
+
43
+ if __name__ == '__main__' :
44
+ n = int (input ())
45
+ print_rangoli (n )
Original file line number Diff line number Diff line change
1
+ """Time Delta Solution """
2
+
3
+
4
+ # -----------------------------------------------------------------------------
5
+ # You are givent two timestams in the format: Day dd Mon yyyy hh:mm:ss +xxxx
6
+ # where +xxxx represents the timezone.
7
+
8
+ # Input Format:
9
+ # The first line contains T, the number of test cases.
10
+ # Each test case contains two lines, representing the t1 and t2 timestamps.
11
+
12
+ # Constraints:
13
+ # input contains only valid timestamps.
14
+ # year is < 3000.
15
+
16
+ # Output Format:
17
+ # Print the absoulte diffrence (t2 - t1) in seconds.
18
+
19
+ # Sample Input:
20
+ # 2
21
+ # Sun 10 May 2015 13:54:36 -0700
22
+ # Sun 10 May 2015 13:54:36 -0000
23
+ # Sat 02 May 2015 19:54:36 +0530
24
+ # Fri 01 May 2015 13:54:36 -0000
25
+
26
+ # Sample Output:
27
+ # 25200
28
+ # 88200
29
+ #------------------------------------------------------------------------------
30
+
31
+ # Imports
32
+ import math
33
+ import os
34
+ import random
35
+ import re
36
+ import sys
37
+ import datetime
38
+
39
+ # Complete the time_delta function below.
40
+ def time_delta (t1 , t2 ):
41
+ """
42
+ Calculate the time delta between two timestamps in seconds.
43
+ """
44
+ # Convert the timestamps to datetime objects
45
+ t1 = datetime .datetime .strptime (t1 , '%a %d %b %Y %H:%M:%S %z' )
46
+ t2 = datetime .datetime .strptime (t2 , '%a %d %b %Y %H:%M:%S %z' )
47
+
48
+ return (t1 - t2 )
49
+
50
+
51
+
52
+ if __name__ == '__main__' :
53
+
54
+ t = int (input ())
55
+
56
+ for itr_t in range (t ):
57
+ t1 = input ()
58
+
59
+ t2 = input ()
60
+
61
+ delta = time_delta (t1 , t2 )
62
+ # print Delta with 1 Decimal Place
63
+ print (round (delta .total_seconds (), 1 ))
64
+
65
+
66
+
67
+
You can’t perform that action at this time.
0 commit comments