0

I've been set the task to design a small game which includes a text file which is 'encrypted' and a 'decrypted' version of the text file. The user is shown the 'encrypted' list (which has been read in and appended to an array) with some clues e.g. A = # (I'm using a dictionary to store possible values of the symbols.)

My problem is: I have created the whole game but i have added an option to my menu to allow the End-User to compare the words they have substituted in with the 'decrypted' list (also read into an array) to see if they have completed the game.

I have tried the following code and have tested the game through to me being 100% sure the words were identical and the Python Shell printed "Sorry! Try Again!"

Here's The Code:

def compareFiles():
    for eachLine in range(len(rsef)):
        if rsef[eachLine] == rssf[eachLine]:
            print("Congratulations! Puzzle Solved!")
        else:
            print("Sorry! Try Again!")
            secMenu()

For Context:

secMenu() is my menu
rsef is my 'encrypted' array
rssf is the 'decrypted' array which i want to compare to.

EDIT:

Which Option Would You Like To Choose?
Option Number: 1
--------------------------------
1. View The Encrypted Words With Some Clues.

A+/084&"
A3MANA+
8N203:
,1$&
!-MN
.A7&33&
AMA71N
&-&641'2
A))85
9&330M

This is the Sorted List:

Which Option Would You Like To Choose?
Option Number: 5

ACQUIRED
ALMANAC
INSULT
JOKE
HYMN
GAZELLE
AMAZON
EYEBROWS
AFFIX
VELLUM
13
  • Does the order matter? Should each element of rsef be the same as the corresponding element in rssf or could they be in any order? Will the two arrays always be the same length? Commented Dec 11, 2013 at 16:08
  • Comparing lists in python is much easier, do arr1[:] == arr2[:] Commented Dec 11, 2013 at 16:09
  • 1
    note that the above code will print a 'pass' or 'fail' message for every line. you really want to collect an overall pass/fail for all lines and then print pass/fail. Commented Dec 11, 2013 at 16:09
  • Mr. E - Well the order is predefined, all the end-user can do is come up with values for the symbols. If it helps, each list has 10 Words. Commented Dec 11, 2013 at 16:10
  • 1
    Nothing there looks like two identical lists, or even like lists. Commented Dec 11, 2013 at 16:18

1 Answer 1

2

Here's to check if all items in both lists are identical:

def compareFiles():
    if rsef == rssf:
        print("Congratulations! Puzzle Solved!")
    else:
        print("Sorry! Try Again!")
        secMenu()

If you insist on looping, the one below :)

def compareFiles():
    for eachLine in range(len(rsef)):
        if rsef[eachLine] != rssf[eachLine]:
            print("Sorry! Try Again!")
            secMenu()
            return 0 #exit the function, use this if you need it.

        print("Congratulations! Puzzle Solved!")
Sign up to request clarification or add additional context in comments.

2 Comments

How could i change my code to check eachLine as i have already stated?
Hm.. What are you going to check? If both are similar?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.