New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Hello guys, I have an assignment task for Python due to tomorrow but i don’t have an idea how to do, can you please help me?
It is a program for guessing a number game. The program generates a random 4-digit number. Then it allows user to guess the number. If the guessed number’s digits match with the target number & they are in the correct location then the program returns a ‘+’ sign for each of these matching digits. If they match but their locations are different then the program returns ‘-‘ for each of these matching digits. For those which don’t match, it returns a blank statement. The program gives 10 tries to the user. If the user guesses it right then it prints a message for winning. Otherwise, it prints the target number.
2 Answers
+ 2
This is the game master mind!
You begin with import random
If four digit number, randint(1000,9999)
But since you need to check each digit, so to prevent turning them into string then splitting, better at beginning use for loop to generate four single digit random number
After that, let a flag called win and default false
Use while loop to run the read input and checking.
+ 1
Gordon, thanks a lot i will give it a try 😅