Answer to Question #335334 in Python for Venkatesh Reddy

Question #335334

Word Rearrange: In word Rearrange players try to score points by forming words using the letters from a 6-letters scrambled word.Given some guessed words,find the total No.of points the players scored in a particular round using the following rubric. 3-letter words are 1 pt, 4-letter words are 2 pts, 5-letter words are 3 pts, 6-letter words are 4 pts+50 pt bonus. A guessed word is invalid if the characters are not present in the scrambled word.Notes-that invalid words count as 0. your task is to find out the final score.

INPUT: The first line contains a string representing a scrambled word. The Second Line contains some spaces-separated strings representing words guessed by the player.


INPUT:

rceast

cat create sat

OUTPUT:

2

INPUT:

tacren

trance recant

OUTPUT:

108


1
Expert's answer
2022-05-01T19:07:00-0400

while True:

  scrambled_w = input('Please, input word => ').lower()

  if scrambled_w.isdigit() == False and len(scrambled_w) == 6:

    break

  else:

    print('Please, input word which lenght = 6')

   

guess_w = input('Please, input words whose characters can be in the scrambled word\n').split()


dct_scr = {}

points = {

  3: 1,

  4: 2,

  5: 3,

  6: 4

  }


total = 0

flag = True


for el in scrambled_w:

  dct_scr[el] = dct_scr.get(el, 0) + 1


for el in guess_w:

  if el.isdigit() == False and 3 <= len(el) <= 6:

    dct_guess = {}

    for c in el:

      dct_guess[c] = dct_guess.get(c, 0) + 1

       

    for key, value in dct_guess.items():

      if key in dct_scr:

        if value != dct_scr[key]:

          flag = False

          break

        else:

          flag = True

      else:

        break

       

    if flag:

      total += points[len(el)]

      if len(el) == 6:

        total += 50


  else:

    continue


print('Your points =', total)



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS