Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Mastermind

def right_inwrongplace(userGuess, number):
    # Create a list of Boolean values representing correct guesses.
    # for exemple: if numbers = [1,2,3,4] and guess = [1,2,9,9], correct_places will be [True,True,False,False]
    correct_places = [True if v == number[i] else False for i, v in enumerate(userGuess)]
    # create a list with only the incorrect guesses.
    g = [v for  i, v in enumerate(userGuess) if not correct_places[i]]
    # create a list with the numbers which weren't guessed correctly.
    n = [v for  i, v in enumerate(number) if not correct_places[i]]
    #return the amount of guesses that are correct but in the wrong place. (the numbers that are in both lists) 
    return len([i for i in g if i in n])
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe passed by reference or value 
Python :: k and M to int in pandas 
Python :: django app directory 
Python :: Half String 
Python :: pytorch_starting 
Python :: improt kmean 
Python :: scrapy pass string as html 
Python :: python file is writable 
Python :: what is proc file 
Python :: numpy split to chunks of equal size 
Python :: neopixel thonny python 
Python :: how to multiply two lists in python 
Python :: django graphene without model 
Python :: create file and store output python 
Python :: scrapy capture: Error downloading 
Python :: paystack python 
Python :: count each value in lsitp ython 
Python :: pafy python documentation 
Python :: Find & set values in pandas Dataframe 
Python :: python send commands in one line but write in multiple 
Python :: snipe cmd python.py 
Python :: python check for int 
Python :: python plot confidence interval 
Python :: yahoo finance python chart 
Python :: pygame get rect 
Python :: python / vs // 
Python :: how to update a python package 
Python :: flask documentation 
Python :: semaphore in python 
Python :: python max with custom function 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =