diff --git a/Basic Scripts/NewPasswordStrength b/Basic Scripts/NewPasswordStrength new file mode 100644 index 0000000..d41deed --- /dev/null +++ b/Basic Scripts/NewPasswordStrength @@ -0,0 +1,89 @@ +''' +Password Strength Checker +------------------------------------------------------------- +''' + + +import string +import getpass + + +def check_password_strength(): + password = getpass.getpass('Enter the password: ') + strength = 0 + remarks = '' + lower_count = upper_count = num_count = wspace_count = special_count = 0 + + for char in list(password): + if char in string.ascii_lowercase: + lower_count += 1 + elif char in string.ascii_uppercase: + upper_count += 1 + elif char in string.digits: + num_count += 1 + elif char == ' ': + wspace_count += 1 + else: + special_count += 1 + + if lower_count >= 1: + strength += 1 + if upper_count >= 1: + strength += 1 + if num_count >= 1: + strength += 1 + if wspace_count >= 1: + strength += 1 + if special_count >= 1: + strength += 1 + + if strength == 1: + remarks = ('That\'s a very bad password.' + ' Change it as soon as possible.') + elif strength == 2: + remarks = ('That\'s a weak password.' + ' You should consider using a tougher password.') + elif strength == 3: + remarks = 'Your password is okay, but it can be improved.' + elif strength == 4: + remarks = ('Your password is hard to guess.' + ' But you could make it even more secure.') + elif strength == 5: + remarks = ('Now that\'s one hell of a strong password!!!' + ' Hackers don\'t have a chance guessing that password!') + + print('Your password has:-') + print(f'{lower_count} lowercase letters') + print(f'{upper_count} uppercase letters') + print(f'{num_count} digits') + print(f'{wspace_count} whitespaces') + print(f'{special_count} special characters') + print(f'Password Score: {strength / 5}') + print(f'Remarks: {remarks}') + + +def check_pwd(another_pw=False): + valid = False + if another_pw: + choice = input( + 'Do you want to check another password\'s strength (y/n) : ') + else: + choice = input( + 'Do you want to check your password\'s strength (y/n) : ') + + while not valid: + if choice.lower() == 'y': + return True + elif choice.lower() == 'n': + print('Exiting...') + return False + else: + print('Invalid input...please try again. \n') + + +if __name__ == '__main__': + print('===== Welcome to Password Strength Checker =====') + check_pw = check_pwd() + while check_pw: + check_password_strength() + check_pw = check_pwd(True) diff --git a/Basic Scripts/NumberOfWords b/Basic Scripts/NumberOfWords new file mode 100644 index 0000000..7276adb --- /dev/null +++ b/Basic Scripts/NumberOfWords @@ -0,0 +1,82 @@ +''' +Numbers To Words +------------------------------------------------------------- +''' + + +ones = ( + 'Zero', 'One', 'Two', 'Three', 'Four', + 'Five', 'Six', 'Seven', 'Eight', 'Nine' + ) + +twos = ( + 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', + 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' + ) + +tens = ( + 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', + 'Seventy', 'Eighty', 'Ninety', 'Hundred' + ) + +suffixes = ( + '', 'Thousand', 'Million', 'Billion' + ) + +def fetch_words(number, index): + if number == '0': return 'Zero' + + number = number.zfill(3) + hundreds_digit = int(number[0]) + tens_digit = int(number[1]) + ones_digit = int(number[2]) + + words = '' if number[0] == '0' else ones[hundreds_digit] + + if words != '': + words += ' Hundred ' + + if tens_digit > 1: + words += tens[tens_digit - 2] + words += ' ' + words += ones[ones_digit] + elif(tens_digit == 1): + words += twos[((tens_digit + ones_digit) % 10) - 1] + elif(tens_digit == 0): + words += ones[ones_digit] + + if(words.endswith('Zero')): + words = words[:-len('Zero')] + else: + words += ' ' + + if len(words) != 0: + words += suffixes[index] + + return words + + +def convert_to_words(number): + length = len(str(number)) + if length > 12: + return 'This program supports a maximum of 12 digit numbers.' + + count = length // 3 if length % 3 == 0 else length // 3 + 1 + copy = count + words = [] + + for i in range(length - 1, -1, -3): + words.append(fetch_words( + str(number)[0 if i - 2 < 0 else i - 2 : i + 1], copy - count)) + + count -= 1 + + final_words = '' + for s in reversed(words): + final_words += (s + ' ') + + return final_words + +if __name__ == '__main__': + number = int(input('Enter any number: ')) + print('%d in words is: %s' %(number, convert_to_words(number))) diff --git a/Games/NewHamgMan b/Games/NewHamgMan new file mode 100644 index 0000000..5ecb0af --- /dev/null +++ b/Games/NewHamgMan @@ -0,0 +1,139 @@ +''' +Hangman Game +------------------------------------------------------------- +''' + + +import random +import time +import os + + +def play_again(): + question = 'Do You want to play again? y = yes, n = no \n' + play_game = input(question) + while play_game.lower() not in ['y', 'n']: + play_game = input(question) + + if play_game.lower() == 'y': + return True + else: + return False + + +def hangman(word): + display = '_' * len(word) + count = 0 + limit = 5 + letters = list(word) + guessed = [] + while count < limit: + guess = input(f'Hangman Word: {display} Enter your guess: \n').strip() + while len(guess) == 0 or len(guess) > 1: + print('Invalid input. Enter a single letter\n') + guess = input( + f'Hangman Word: {display} Enter your guess: \n').strip() + + if guess in guessed: + print('Oops! You already tried that guess, try again!\n') + continue + + if guess in letters: + letters.remove(guess) + index = word.find(guess) + display = display[:index] + guess + display[index + 1:] + + else: + guessed.append(guess) + count += 1 + if count == 1: + time.sleep(1) + print(' _____ \n' + ' | \n' + ' | \n' + ' | \n' + ' | \n' + ' | \n' + ' | \n' + '__|__\n') + print(f'Wrong guess: {limit - count} guesses remaining\n') + + elif count == 2: + time.sleep(1) + print(' _____ \n' + ' | | \n' + ' | | \n' + ' | \n' + ' | \n' + ' | \n' + ' | \n' + '__|__\n') + print(f'Wrong guess: {limit - count} guesses remaining\n') + + elif count == 3: + time.sleep(1) + print(' _____ \n' + ' | | \n' + ' | | \n' + ' | | \n' + ' | \n' + ' | \n' + ' | \n' + '__|__\n') + print(f'Wrong guess: {limit - count} guesses remaining\n') + + elif count == 4: + time.sleep(1) + print(' _____ \n' + ' | | \n' + ' | | \n' + ' | | \n' + ' | O \n' + ' | \n' + ' | \n' + '__|__\n') + print(f'Wrong guess: {limit - count} guesses remaining\n') + + elif count == 5: + time.sleep(1) + print(' _____ \n' + ' | | \n' + ' | | \n' + ' | | \n' + ' | O \n' + ' | /|\ \n' + ' | / \ \n' + '__|__\n') + print('Wrong guess. You\'ve been hanged!!!\n') + print(f'The word was: {word}') + + if display == word: + print(f'Congrats! You have guessed the word \'{word}\' correctly!') + break + + +def play_hangman(): + print('\nWelcome to Hangman\n') + name = input('Enter your name: ') + print(f'Hello {name}! Best of Luck!') + time.sleep(1) + print('The game is about to start!\nLet\'s play Hangman!') + time.sleep(1) + os.system('cls' if os.name == 'nt' else 'clear') + + words_to_guess = [ + 'january', 'border', 'image', 'film', 'promise', 'kids', + 'lungs', 'doll', 'rhyme', 'damage', 'plants', 'hello', 'world' + ] + play = True + while play: + word = random.choice(words_to_guess) + hangman(word) + play = play_again() + + print('Thanks For Playing! We expect you back again!') + exit() + + +if __name__ == '__main__': + play_hangman()