Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Anagram Game

import json
import random
with open('E:python files/data.json') as f:
  data = json.load(f)

def word_prompt(data, length):
    all_words = list(data.keys())
    while True:
        word = random.choice(all_words)
        if len(word) < length and len(word) > 2:
            return word
def shuffle_word(word):
    array = list(word)
    shuffled = word
    while True:
        random.shuffle(array)
        shuffled = ''.join(array)
        if shuffled != word:
            return shuffled
print("Welcome to the Anagram Game!")
while(True):
    word = word_prompt(data, 5)
    question = shuffle_word(word)
    meaning = data[word]
    
    question = question.lower()
    word = word.lower()
    
    print("
Solve:", question)
    print("Hint:", meaning)
 
    for i in range(5, 0, -1):
        print("
Attempts Left:", i)
        guess = input('Make a guess: ').lower()
        if guess == word:
            print("Correct!")
            break
        if i == 1:
            print("
Correct Answer:", word)
    
    choice = input("
Continue? [y/n]: ")
    print('-'*50)
    if choice == 'n':
        print("
Thank you for playing!")
        break
Comment

PREVIOUS NEXT
Code Example
Python :: precondition error tensorflow predict 
Python :: django rest framework not getting form 
Python :: run exe for python and wait until finish 
Python :: how to create a login page in python 
Python :: flask Upload file to local s3 
Python :: playlist discordpy 
Python :: label default text value python 
Python :: pandas set column to value using mask 
Python :: python time a code segment 
Python :: if function has no argument python 
Python :: grepper how to use fraction 
Python :: how to print the text new line instead of n in jupyter notebook 
Python :: kinect python exoskeleton 
Python :: python getattr function 
Python :: divide array into equal parts/slices python 
Python :: Reset Python Dictionary to 0 Zero. Empty existing Python Dictionary 
Python :: how to put 2 code n 1 line in python 
Python :: transpose 3d matrix pytorch 
Python :: sns regplot make the line and confidence interval thicker 
Python :: python cv2 blob detection seg fault 
Python :: cosine similiarity OF A VECTOR WITH OTHER VECTORS IN A MATRIX 
Python :: pristine 
Python :: algorithme pour afficher table de multiplication python 
Python :: pandas series add prefix 
Python :: python wikipedia 
Python :: python remove list from nested list 
Python :: python select random number from list 
Python :: python endless loop 
Python :: list input python 
Python :: if with && in python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =