Answer to Question #345321 in Python for Mukesh

Question #345321

Write a program to print the following output.


Input

The first line contains a string.

The second line contains some space-separated strings.


Output

The output should be a single integer.


Explanation

scramble word = "tacren"

guessed words = ["trance", "recant"]


Since "trance" and "recant" both have length 6 then you score 54 pts each.

So the output is 108.


Sample Input1

rceast

cat create sat

Sample Output1

2


Sample Input2

tacren

trance recant

Sample Output2

108



1
Expert's answer
2022-05-26T14:07:43-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