Skip to content

Commit ca544dc

Browse files
committed
3 useful script added to repo: 1-create rangoli art , time delta between 2 event base on UTC ,Caretesian seri Calculation
1 parent 461ed00 commit ca544dc

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

cartesian_product.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+

rangoli.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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)

time_delta.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+

0 commit comments

Comments
 (0)