Advertisement
_s8

Untitled

_s8
Nov 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. points = 0
  5. rounds = int(input("How many rounds of scrabble?"))
  6. lengths = []
  7. new = open('words.txt', 'r')
  8. word_list = new.readlines()
  9. new.close()
  10. letters = []
  11. common_letters = []
  12. for word in word_list:
  13.     lengths.append(len(word))
  14.     for letter in word:
  15.         letters.append(letter)
  16. for x in range(0, len(letters)):
  17.     if letters.count(letters[x])>1 and letters[x] not in common_letters:
  18.         common_letters.append(letters[x])
  19. common_letters.remove('\n')
  20.  
  21. for r in range(1, rounds+1):
  22.     letters_available = ''
  23.     for n in range(0, max(lengths)):
  24.         choice = random.choice(common_letters)
  25.         while choice in letters_available:
  26.             choice = random.choice(common_letters)
  27.         letters_available += choice
  28.         if n == max(lengths)-1:
  29.             pass
  30.         else:
  31.             letters_available += ', '
  32.     printable = letters_available
  33.     letters_available = letters_available.replace(', ', '')
  34.     print("Round {}:\n".format(r))
  35.     guess = input("What words can you make from {} ? ".format(printable))
  36.     guess = guess.replace(' ', '')
  37.     correct = 0
  38.     if guess+'\n' not in word_list:
  39.         print(guess,"is not a word!")
  40.     else:
  41.         for letter in letters_available:
  42.             if letter in guess:
  43.                 correct += 1
  44.         if correct == len(guess):
  45.             print("Correct! You get {} points!".format(len(guess)))
  46.             points += len(guess)
  47.         else:
  48.             print("Incorrect! You get {} points since you got {} letters right!".format(correct, correct))
  49. print("You finished {} rounds with {} points!".format(rounds, points))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement