Python Forum
Guessing game with 4 different digits
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guessing game with 4 different digits
#1
Hi,

I'm new to programming and I need to make a guessing game.
Python needs to generate a random code containing 4 digits, the 4 digits have to all be different and can only be numbers from 1 to 9.
The player gets 15 turns to guess the code. With each try the player gets feedback about which numbers are correct but are in the wrong place, or which numbers are correct and are in the right place.

I've been trying different approaches for the last couple of days but can't seem to figure it out.

Help please?
Reply
#2
(Mar-28-2020, 10:42 AM)LinseyLogi Wrote: I've been trying different approaches for the last couple of days but can't seem to figure it out.
Show what have you tried so far.
Post your code in python tags. Full traceback, if you get any - in error tags. Ask specific question(s).
See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
show what you have tried, and where you need help.
Reply
#4
import random
a = 1
for a in range(1,8):
    for b in range(1,8):
        if a!= b:
            for c in range (1,8):
                if b!=c and a!=c:
                    for d in range (1,8):
                        if c!=d and b!=d and a!=d:
                            number = a,b,c,d
                            print(number)
Reply
#5
Please show where you have gone wrong
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#6
It generates all possible combinations, while I just need one random 4 digit number.
Reply
#7
How about using random.randint? It picks a random integer and then you can print it out
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Play again, in a guessing game banidjamali 4 11,884 Jan-22-2021, 06:23 AM
Last Post: banidjamali
  Help - random number/letter guessing game juin22 1 3,239 Aug-16-2020, 06:36 AM
Last Post: DPaul
  making a guessing number game blacklight 1 2,225 Jul-02-2020, 12:21 AM
Last Post: GOTO10
  Guessing game with comparison operators Drone4four 9 13,871 Dec-02-2018, 06:12 PM
Last Post: ichabod801
  Guessing Game "limit 4 attempts" help rprollin 3 19,864 Jun-23-2018, 04:37 PM
Last Post: ljmetzger
  Name guessing game in python Liquid_Ocelot 6 15,120 Apr-01-2017, 12:52 PM
Last Post: ichabod801
  guessing script simon 3 5,648 Oct-10-2016, 01:47 PM
Last Post: simon
  trying to get my random number guessing game to work! NEED HELP RaZrInSaNiTy 4 6,951 Oct-06-2016, 12:49 AM
Last Post: tinabina22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020