-2
\$\begingroup\$

Here is my code:

https://gist.github.com/Salil03/5fb4d512b97324c89e2580f94725a7fd

The instructions are printed out from the python file.

They are given here for convienience

  1. You start by typing in a letter

  2. The computer then types another letter and the cycle repeats Example: You type: z Computer types: a

  3. You know that zambia and zaire start with ""za""." "

  4. So the next letter you type must me ""m"" or ""i"". But, you must type" """m"" because the last letter of zambia will end on the computer." On the other hand, last letter of zaire will end on you.

  5. The person on which the last letter ends, loses. Example: Computer loses on sweden You lose on dubai

  6. If you don't know any place you can type in ""Challenge""." The computer will give you the answer and you will lose.

  7. If the computer doesn't know the answer, he will say ""Challenge""" Then two things can happen:

1) You know the right answer and the moderator says it is correct and you win.

or

2) You don't know the right answer and you type in gibberish and the moderator marks it as wrong and you lose

  1. Whenever you think the computer has typed in the last letter of a place, press enter.

I'm looking for comments about the following points:

  1. coding style
  2. performance
  3. Readability of code
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review. Can you include your code also? It is expected for reviews here. codereview.stackexchange.com/help/how-to-ask \$\endgroup\$ – chicks Jul 10 '18 at 17:32
  • \$\begingroup\$ @chicks The code is big so I included a link for it \$\endgroup\$ – Agile_Eagle Jul 10 '18 at 17:33
  • \$\begingroup\$ Welcome to Code Review! Unfortunately your question is off-topic as of now, as the code to be reviewed must be present in the question. Please add the code you want reviewed in your question. Thanks! \$\endgroup\$ – Malachi Jul 10 '18 at 18:26
  • \$\begingroup\$ @Malachi the formatting of the code gets disturbed if I add it in the question \$\endgroup\$ – Agile_Eagle Jul 10 '18 at 18:27
  • \$\begingroup\$ @Agile_Eagle: We can attempt to fix it in that case. \$\endgroup\$ – Jamal Aug 13 '18 at 23:30
0
\$\begingroup\$

By far the most important thing you can change is splitting your code up into smaller functions. For example, every time you print with random colors, that could be a function:

def print_colored(str, n=1):
    for i, x in enumerate(str):
        if i % n == 0:
                print(x, end='')
                sys.stdout.flush()
                os.system("color " + str(randint(1, 8)))
            else:
                print(x, end='')
                sys.stdout.flush()

Things like your main game loop can also be made a function to hide variables and make your code easier to read.

Seperation of concerns is very important in programming. In it's current state, I cant tell what is going on with out reading and understanding the entire program at once.

\$\endgroup\$
  • \$\begingroup\$ I will keep that in mind \$\endgroup\$ – Agile_Eagle Jul 10 '18 at 16:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.