diff --git a/AREA OF TRIANGLE1.py b/AREA OF TRIANGLE1.py new file mode 100644 index 00000000000..76acd962e9f --- /dev/null +++ b/AREA OF TRIANGLE1.py @@ -0,0 +1,17 @@ +# Python Program to find the area of triangle +#calculates area of traingle in efficient way!! +a = 5 +b = 6 +c = 7 + +# Uncomment below to take inputs from the user +# a = float(input('Enter first side: ')) +# b = float(input('Enter second side: ')) +# c = float(input('Enter third side: ')) + +# calculate the semi-perimeter +s = (a + b + c) / 2 + +# calculate the area +area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 +print('The area of the triangle is %0.2f' %area) \ No newline at end of file diff --git a/AREA OF TRIANGLE2.py b/AREA OF TRIANGLE2.py new file mode 100644 index 00000000000..9e8386ed4fd --- /dev/null +++ b/AREA OF TRIANGLE2.py @@ -0,0 +1,13 @@ +a = 5 +b = 6 +c = 7 +# a = float(input('Enter first side: ')) +# b = float(input('Enter second side: ')) +# c = float(input('Enter third side: ')) + +# calculate the semi-perimeter +s = (a + b + c) / 2 + +# calculate the area +area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 +print('The area of the triangle is %0.2f' %area) \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000000..22d660a0251 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.8" diff --git a/Python Program to Remove Punctuations From a String1.py b/Python Program to Remove Punctuations From a String1.py new file mode 100644 index 00000000000..e30a3b90e1a --- /dev/null +++ b/Python Program to Remove Punctuations From a String1.py @@ -0,0 +1,16 @@ +# define punctuation +punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' + +my_str = "Hello!!!, he said ---and went." + +# To take input from the user +# my_str = input("Enter a string: ") + +# remove punctuation from the string +no_punct = "" +for char in my_str: + if char not in punctuations: + no_punct = no_punct + char + +# display the unpunctuated string +print(no_punct) \ No newline at end of file diff --git a/Python Program to Remove Punctuations From a String2.py b/Python Program to Remove Punctuations From a String2.py new file mode 100644 index 00000000000..288e937f876 --- /dev/null +++ b/Python Program to Remove Punctuations From a String2.py @@ -0,0 +1,18 @@ +punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' + +my_str = "Hello!!!, he said ---and went." + +no_punct = "" +patch-2 +for char in my_str: + if char not in punctuations: + no_punct = no_punct + char + +for char in my_str: + +if char not in punctuations: + +no_punct = no_punct + char + +master +print(no_punct) \ No newline at end of file diff --git a/Random Password Generator1.py b/Random Password Generator1.py new file mode 100644 index 00000000000..5b01582cc82 --- /dev/null +++ b/Random Password Generator1.py @@ -0,0 +1,11 @@ +import random + +low="abcdefghijklmnopqrstuvwxyz" +upp="ABCDEFGHIJKLMNOPQRSTUVWXYZ" +num="0123456789" +sym="!@#$%^&*" + +all=low+upp+num+sym +length=8 +password="".join(random.sample(all,length)) +print(password) diff --git a/Random Password Generator2.py b/Random Password Generator2.py new file mode 100644 index 00000000000..0b1edc1c6d6 --- /dev/null +++ b/Random Password Generator2.py @@ -0,0 +1,57 @@ +import random + +LOWERCASE_CHARS = tuple(map(chr, xrange(ord('a'), ord('z')+1))) +UPPERCASE_CHARS = tuple(map(chr, xrange(ord('A'), ord('Z')+1))) +DIGITS = tuple(map(str, range(0, 10))) +SPECIALS = ('!', '@', '#', '$', '%', '^', '&', '*') + +SEQUENCE = (LOWERCASE_CHARS, + UPPERCASE_CHARS, + DIGITS, + SPECIALS, + ) + +def generate_random_password(total, sequences): + r = _generate_random_number_for_each_sequence(total, len(sequences)) + + password = [] + for (population, k) in zip(sequences, r): + n = 0 + while n < k: + position = random.randint(0, len(population)-1) + password += population[position] + n += 1 + random.shuffle(password) + + while _is_repeating(password): + random.shuffle(password) + + return ''.join(password) + +def _generate_random_number_for_each_sequence(total, sequence_number): + """ Generate random sequence with numbers (greater than 0). + The number of items equals to 'sequence_number' and + the total number of items equals to 'total' + """ + current_total = 0 + r = [] + for n in range(sequence_number-1, 0, -1): + current = random.randint(1, total - current_total - n) + current_total += current + r.append(current) + r.append(total - sum(r)) + random.shuffle(r) + + return r + +def _is_repeating(password): + """ Check if there is any 2 characters repeating consecutively """ + n = 1 + while n < len(password): + if password[n] == password[n-1]: + return True + n += 1 + return False + +if __name__ == '__main__': + print generate_random_password(random.randint(6, 30), SEQUENCE) \ No newline at end of file