Exemplo n.º 1
0
def anagram():
    if request.method == 'POST':
        submitted = request.get_json(force=True)
        length = submitted["length"]
        anagram = make_anagram(get_word(length, FULL_WORD_LIST))
        answers = anagram_answers(len(anagram), anagram, DICTIONARY)
        return jsonify(data(anagram, answers))
    return render_template("anagram.html")
Exemplo n.º 2
0
def hangman():
    word = functions.get_word()
    guesses = -1
    game_word = [char.upper() for char in word]
    game_word_display = [" _ " for char in word]
    game_done = [" _ " for char in word]
    wrong_guesses = []

    functions.start_screen()
    print("Please press enter to begin!!")

    while True:
        user = str(input(" -- > ")).casefold()

        # This `if` statement makes sure that the initial value of -1 doesn't
        # get passed on if the user gets a correct guess on their first turn
        if user.upper() in game_word:
            if guesses == -1:
                guesses = 0
            functions.game_screen(guesses)

            for i in range(len(game_word)):
                if user.upper() == game_word[i]:
                    # Updates the game to display the newly discovered letters
                    game_word_display[i] = user.upper()
                    # Removes letters that have been found from `game_word`
                    game_word[i] = " _ "

            print(game_word_display)
            print(f"Wrong guesses: {wrong_guesses}")

            # When all the letters in `game_word` are found and removed
            # `game_word` will equal `game_done`
            if game_word == game_done:
                functions.win_screen()
                break

        else:

            if user not in wrong_guesses and user.isalpha():
                wrong_guesses.append(user.upper())

            guesses += 1
            functions.game_screen(guesses)
            print(game_word_display)
            print(f"Wrong guesses: {wrong_guesses}")
            if guesses == 7:
                functions.lose_screen(word.upper())
                break
Exemplo n.º 3
0
import argparse
import glob
import functions as fn

## Init

# arguments
parser = argparse.ArgumentParser(description='Simple password generator')
parser.add_argument('--count',
                    type=int,
                    default='5',
                    help='number of password(s) to return')
args = parser.parse_args()

# var
wordlists = glob.glob('wordlists//*.txt')

## Main

for i in range(0, args.count):
    got_word = fn.get_word(wordlists)
    got_int = fn.get_int()
    print(got_word + '#' + got_int)
Exemplo n.º 4
0
try:
    if first_time:
        action = '0'
        first_time = False
    else:
        # Gives the user a menu of actions to choose from
        action = functions.get_action()
        # Reloads the functions file if it's been updated
        mod_time = functions.update_functions(functions, mod_time)
    # Executes the appropriate feature depending on the action choice
    if action == '0':
        # Lets the user choose a new text file
        text, filename = functions.get_text()
    elif action == '1':
        # Counts how many times a word or phrase appears
        word = functions.get_word("Please enter a word or phrase to "
                                  "find in the text: ")
        functions.print_frequency(text, word)
    elif action == '2':
        # Prints all instances of a word or phrase
        word = functions.get_word("Please enter a word or phrase to "
                                  "find in the text: ")
        functions.print_instances(text, word)
    elif action == '3':
        # Replaces a word or phrase with another word or phrase
        old_word = functions.get_word("Please enter a word or phrase to "
                                      "find in the text: ")
        new_word = functions.get_word("Please enter a word or phrase to "
                                      "replace '%s': " % old_word.lower())
        functions.replace_word(text, filename, old_word, new_word)
    elif action == '4':
        # Caesar-shifts all letters in the text by a desired amount
Exemplo n.º 5
0
#PLayer decides to load a previously saved game, choice of 2 slots
if load_game == 'y' or load_game == 'yes':
    name,score,round_count = load_on_startup()
    #Plater is welcomed back, displays previous score and round count
    print("Welcome back {}. Your score is {}/{}".format(name,score,round_count))
#if player decides not to load then default score and round count are used
else:
    score = 0
    round_count = 0

#MainGame, While can be restarted once round is over
while True:
    tries = 10 #Number of 'lives' a player has
    used_letters = [] #Already played letters
    round_count += 1 #Increment the round_count to aid scoring
    word = get_word() #Use get_word() function to read words.txt and randomly select a word
    word_list = list(word) #Converts the word string into a list
    answer = []#Blank answer list
    
    #add "_" to the answer list, in place of each character in the word
    for letter in word_list:
        answer.append("_") 
    #Prints the number of '_' as a string followed by prompt for player to guess a letter
    print(' '.join(answer))
    print("\nGuess a letter")
    guess = input("> ").lower()
    #Player must guess a single letter otherwise an error is displayed, also not one that has already been tried
    while tries > 0 and "_" in answer and  guess != "give up":
        if guess.isdigit(): #checks if input is a number
            print("Please use letters only")
            guess = input("> ").lower()