Skip to content
Advertisement

Python, User picks a word and computer guesses it

First off I am a noob to python (if you couldn’t tell) and a noob to StackOverflow.

I’ve seen similar programs but I can’t find ones that quite give me much help. In short, the assignment I’m doing is to create a program that takes a word from the user and proceeds to guess random letters.

Currently, my new_letter function doesn’t work I’ve tried printing in several places so I know that it just doesn’t get through the function.

I was trying to come up with a counter so that the guessed letter would replace the * in computers_word in the right spot that corresponds with the same place in actual_word.

JavaScript

^ Okay as of now the program gets to here and just stops, I don’t get any errors it’s just the new_letter function isn’t returning anything.

JavaScript

Advertisement

Answer

Okay. So, to start off as @Uvar pointed out, the assignment and comparison has been mixed up at several places. Additionally, the code could run for very long duration because of the while loop and indiscriminate picking of values between 0-25. The code doesn’t eliminate previously guessed digits in future guesses. The modified code (with comments) is as follows:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement