From ca544dcfb290d8f22a7a2cbb6023967a9d259583 Mon Sep 17 00:00:00 2001 From: Hamid Reza Bakhtaki <62337833+Bakhtaki@users.noreply.github.com> Date: Mon, 11 Jul 2022 15:48:20 +0430 Subject: [PATCH] 3 useful script added to repo: 1-create rangoli art , time delta between 2 event base on UTC ,Caretesian seri Calculation --- cartesian_product.py | 25 +++++++++++++++++ rangoli.py | 45 +++++++++++++++++++++++++++++ time_delta.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 cartesian_product.py create mode 100644 rangoli.py create mode 100644 time_delta.py diff --git a/cartesian_product.py b/cartesian_product.py new file mode 100644 index 00000000000..7ed49aae295 --- /dev/null +++ b/cartesian_product.py @@ -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) + diff --git a/rangoli.py b/rangoli.py new file mode 100644 index 00000000000..75191e08546 --- /dev/null +++ b/rangoli.py @@ -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) diff --git a/time_delta.py b/time_delta.py new file mode 100644 index 00000000000..9b153fd9707 --- /dev/null +++ b/time_delta.py @@ -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)) + + + +