Skip to content

Commit

Permalink
3 useful script added to repo: 1-create rangoli art , time delta betw…
Browse files Browse the repository at this point in the history
…een 2 event base on UTC ,Caretesian seri Calculation
  • Loading branch information
Bakhtaki committed Jul 11, 2022
1 parent 461ed00 commit ca544dc
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cartesian_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Cartesian Product of Two Lists."""

# Import
from itertools import product


# Cartesian Product of Two Lists
def cartesian_product(list1, list2):
"""Cartesian Product of Two Lists."""
for _i in list1:
for _j in list2:
print((_i, _j), end=' ')


# Main
if __name__ == '__main__':
list1 = input().split()
list2 = input().split()

# Convert to ints
list1 = [int(i) for i in list1]
list2 = [int(i) for i in list2]

cartesian_product(list1, list2)

45 changes: 45 additions & 0 deletions rangoli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Rangoli Model"""


# Prints a rangoli of size n
def print_rangoli(n):
"""Prints a rangoli of size n"""
# Width of the rangoli
width = 4 * n - 3

# String to be printed
string = ""

# Loop to print the rangoli
for i in range(1, n + 1):
for j in range(0, i):
string += chr(96 + n - j)
if len(string) < width:
string += "-"

for k in range(i - 1, 0, -1):
string += chr(97 + n - k)
if len(string) < width:
string += "-"

print(string.center(width, "-"))
string = ""

for i in range(n - 1, 0, -1):
for j in range(0, i):
string += chr(96 + n - j)
if len(string) < width:
string += "-"

for k in range(i - 1, 0, -1):
string += chr(97 + n - k)
if len(string) < width:
string += "-"

print(string.center(width, "-"))
string = ""


if __name__ == '__main__':
n = int(input())
print_rangoli(n)
67 changes: 67 additions & 0 deletions time_delta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Time Delta Solution """


# -----------------------------------------------------------------------------
# You are givent two timestams in the format: Day dd Mon yyyy hh:mm:ss +xxxx
# where +xxxx represents the timezone.

# Input Format:
# The first line contains T, the number of test cases.
# Each test case contains two lines, representing the t1 and t2 timestamps.

# Constraints:
# input contains only valid timestamps.
# year is < 3000.

# Output Format:
# Print the absoulte diffrence (t2 - t1) in seconds.

# Sample Input:
# 2
# Sun 10 May 2015 13:54:36 -0700
# Sun 10 May 2015 13:54:36 -0000
# Sat 02 May 2015 19:54:36 +0530
# Fri 01 May 2015 13:54:36 -0000

# Sample Output:
# 25200
# 88200
#------------------------------------------------------------------------------

# Imports
import math
import os
import random
import re
import sys
import datetime

# Complete the time_delta function below.
def time_delta(t1, t2):
"""
Calculate the time delta between two timestamps in seconds.
"""
# Convert the timestamps to datetime objects
t1 = datetime.datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
t2 = datetime.datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')

return (t1 - t2)



if __name__ == '__main__':

t = int(input())

for itr_t in range(t):
t1 = input()

t2 = input()

delta = time_delta(t1, t2)
# print Delta with 1 Decimal Place
print(round(delta.total_seconds(), 1))




0 comments on commit ca544dc

Please sign in to comment.