scramble.py

Created by ews31415

Created on June 30, 2023

1.53 KB

Game: Unscramble five-letter words


# 2023-06-30 EWS
# Random Simulation
from random import *

# scramble a word


# word list
words=['acorn','total','shake','world','royal','jelly','first','likes','apple','opera','mouse','crash','truck','boxes','bonus','eagle','house','trick','sleep','black','white','blimp','watch','round','first','hairy','flame','flash','prove','color','nurse','truck','ghost','start','chest','proud','fresh','kitty','seven','quote','rigid','worst','light','minus','faith','grape','ninth','glove','smoke','khaki','elite','brown','bring','brick','bliss','learn','tulip','whale','glide','guide','pound','sheet','death','birth','clear','twist','timed','walks','money','lists','ocean','grind','zooms','steep','crust','spoil','guest','thick','valve','shirt','shrug','happy','blaze','grand','puppy','solid','erase','their','lunch','maybe','every','about','thump','music','sugar','think','false','ozone']
nw=len(words)
print(nw)
# score
score=0
# game length
sgame=10

for i in range(sgame):
  # original word
  j=randint(0,nw-1)
  oword=words[j]
  words.remove(oword)
  nw-=1
  # make lists, initialization
  l1=list(oword)
  l2=l1
  l3=[]
  n=len(l1)
  k=n
  nword=''
  
  # scramble
  for i1 in range(n):
    j=randint(0,k-1)
    w=l2[j]
    nword=nword+w
    l2.remove(w)
    k-=1
  # now the game
  print('Word '+str(i+1)+' of '+str(sgame))
  print('The scrambled word is: '+nword)
  gword=str(input('Your guess? '))
  if oword==gword:
    print('Correct!')
    score+=1
  else:
    print('The word is '+oword)
  print("\n-------\n")

print('Final score: '+str(score))