From cd37633be7724e06021432a1d998e84ebd200241 Mon Sep 17 00:00:00 2001 From: Kp019 Date: Fri, 21 Oct 2022 07:58:39 +0300 Subject: [PATCH 1/3] hack commit --- Hangman game.py | 0 Morsecode generator.py | 97 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Hangman game.py create mode 100644 Morsecode generator.py diff --git a/Hangman game.py b/Hangman game.py new file mode 100644 index 0000000..e69de29 diff --git a/Morsecode generator.py b/Morsecode generator.py new file mode 100644 index 0000000..2593b4a --- /dev/null +++ b/Morsecode generator.py @@ -0,0 +1,97 @@ +MORSE_CODE_DICT = {'A': '.-', 'B': '-...', + 'C': '-.-.', 'D': '-..', 'E': '.', + 'F': '..-.', 'G': '--.', 'H': '....', + 'I': '..', 'J': '.---', 'K': '-.-', + 'L': '.-..', 'M': '--', 'N': '-.', + 'O': '---', 'P': '.--.', 'Q': '--.-', + 'R': '.-.', 'S': '...', 'T': '-', + 'U': '..-', 'V': '...-', 'W': '.--', + 'X': '-..-', 'Y': '-.--', 'Z': '--..', + '1': '.----', '2': '..---', '3': '...--', + '4': '....-', '5': '.....', '6': '-....', + '7': '--...', '8': '---..', '9': '----.', + '0': '-----', ', ': '--..--', '.': '.-.-.-', + '?': '..--..', '/': '-..-.', '-': '-....-', + '(': '-.--.', ')': '-.--.-'} + +# Function to encrypt the string +# according to the morse code chart + + +def encrypt(message): + cipher = '' + for letter in message: + if letter != ' ': + + # Looks up the dictionary and adds the + # corresponding morse code + # along with a space to separate + # morse codes for different characters + cipher += MORSE_CODE_DICT[letter] + ' ' + else: + # 1 space indicates different characters + # and 2 indicates different words + cipher += ' ' + + return cipher + +# Function to decrypt the string +# from morse to english + + +def decrypt(message): + + # extra space added at the end to access the + # last morse code + message += ' ' + + decipher = '' + citext = '' + for letter in message: + + # checks for space + if (letter != ' '): + + # counter to keep track of space + i = 0 + + # storing morse code of a single character + citext += letter + + # in case of space + else: + # if i = 1 that indicates a new character + i += 1 + + # if i = 2 that indicates a new word + if i == 2: + + # adding space to separate words + decipher += ' ' + else: + + # accessing the keys using their values (reverse of encryption) + decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT + .values()).index(citext)] + citext = '' + + return decipher + +# Hard-coded driver function to run the program + + +def main(): + message = input("type the message : ") + result = encrypt(message.upper()) + print(result) + + +''' + message = "--. . . -.- ... -....- ..-. --- .-. -....- --. . . -.- ... " + result = decrypt(message) + print(result) +''' + +# Executes the main function +if __name__ == '__main__': + main() From 260f958c33a5e3b2a8e2959318bf51f93b6079b6 Mon Sep 17 00:00:00 2001 From: Kp019 Date: Fri, 21 Oct 2022 08:00:59 +0300 Subject: [PATCH 2/3] python --- Hangman game.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/Hangman game.py b/Hangman game.py index e69de29..3665da2 100644 --- a/Hangman game.py +++ b/Hangman game.py @@ -0,0 +1,80 @@ +import random +from collections import Counter + +someWords = 'apple banana mango' + +someWords = someWords.split(' ') +# randomly choose a secret word from our "someWords" LIST. +word = random.choice(someWords) + +if __name__ == '__main__': + print('Guess the word! HINT: word is a name of a fruit') + + for i in word: + # For printing the empty spaces for letters of the word + print('_', end=' ') + print() + + playing = True + # list for storing the letters guessed by the player + letterGuessed = '' + chances = len(word) + 2 + correct = 0 + flag = 0 + try: + while (chances != 0) and flag == 0: # flag is updated when the word is correctly guessed + print() + chances -= 1 + + try: + guess = str(input('Enter a letter to guess: ')) + except: + print('Enter only a letter!') + continue + + # Validation of the guess + if not guess.isalpha(): + print('Enter only a LETTER') + continue + elif len(guess) > 1: + print('Enter only a SINGLE letter') + continue + elif guess in letterGuessed: + print('You have already guessed that letter') + continue + + # If letter is guessed correctly + if guess in word: + # k stores the number of times the guessed letter occurs in the word + k = word.count(guess) + for _ in range(k): + letterGuessed += guess # The guess letter is added as many times as it occurs + + # Print the word + for char in word: + if char in letterGuessed and (Counter(letterGuessed) != Counter(word)): + print(char, end=' ') + correct += 1 + # If user has guessed all the letters + # Once the correct word is guessed fully, + elif (Counter(letterGuessed) == Counter(word)): + # the game ends, even if chances remain + print("The word is: ", end=' ') + print(word) + flag = 1 + print('Congratulations, You won!') + break # To break out of the for loop + break # To break out of the while loop + else: + print('_', end=' ') + + # If user has used all of his chances + if chances <= 0 and (Counter(letterGuessed) != Counter(word)): + print() + print('You lost! Try again..') + print('The word was {}'.format(word)) + + except KeyboardInterrupt: + print() + print('Bye! Try again.') + exit() From 6aad6a50eb7cf1394e8f68d8774155afa02761e6 Mon Sep 17 00:00:00 2001 From: Kp019 Date: Fri, 21 Oct 2022 08:01:50 +0300 Subject: [PATCH 3/3] commit --- Hangman game.py | 80 ------------------------------------------------- 1 file changed, 80 deletions(-) diff --git a/Hangman game.py b/Hangman game.py index 3665da2..e69de29 100644 --- a/Hangman game.py +++ b/Hangman game.py @@ -1,80 +0,0 @@ -import random -from collections import Counter - -someWords = 'apple banana mango' - -someWords = someWords.split(' ') -# randomly choose a secret word from our "someWords" LIST. -word = random.choice(someWords) - -if __name__ == '__main__': - print('Guess the word! HINT: word is a name of a fruit') - - for i in word: - # For printing the empty spaces for letters of the word - print('_', end=' ') - print() - - playing = True - # list for storing the letters guessed by the player - letterGuessed = '' - chances = len(word) + 2 - correct = 0 - flag = 0 - try: - while (chances != 0) and flag == 0: # flag is updated when the word is correctly guessed - print() - chances -= 1 - - try: - guess = str(input('Enter a letter to guess: ')) - except: - print('Enter only a letter!') - continue - - # Validation of the guess - if not guess.isalpha(): - print('Enter only a LETTER') - continue - elif len(guess) > 1: - print('Enter only a SINGLE letter') - continue - elif guess in letterGuessed: - print('You have already guessed that letter') - continue - - # If letter is guessed correctly - if guess in word: - # k stores the number of times the guessed letter occurs in the word - k = word.count(guess) - for _ in range(k): - letterGuessed += guess # The guess letter is added as many times as it occurs - - # Print the word - for char in word: - if char in letterGuessed and (Counter(letterGuessed) != Counter(word)): - print(char, end=' ') - correct += 1 - # If user has guessed all the letters - # Once the correct word is guessed fully, - elif (Counter(letterGuessed) == Counter(word)): - # the game ends, even if chances remain - print("The word is: ", end=' ') - print(word) - flag = 1 - print('Congratulations, You won!') - break # To break out of the for loop - break # To break out of the while loop - else: - print('_', end=' ') - - # If user has used all of his chances - if chances <= 0 and (Counter(letterGuessed) != Counter(word)): - print() - print('You lost! Try again..') - print('The word was {}'.format(word)) - - except KeyboardInterrupt: - print() - print('Bye! Try again.') - exit()