Sorry if this is a obvious question, but I am 12 and trying to write some code to help me with my science project, where I am trying to see which lock is the most secure. Basically my problem is, I need to figure out how to compare the output of a function with the if somethinghere() == somethingelse(). And by the way, I am using the random
module. As an example of what im trying to do, this is the comparing code part:
def guessfixed(y):
y = print ("[",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),"]",sep="") #this is supposed to keep changing until it is the same as the key.
return y
for one part that I am comparing, all the [, ] things are to format it to compare it, and the other part I am comparing is
mylistkey = [] # the random generated key, this is supposed to stay the same.
for i in range(0,5):
x = random.randint(0,9)
mylistkey.append(x)
and how I am trying to compare it is with:
while guessfixed(0) != mylistkey:
if guessfixed(0) == mylistkey:
print ("it worked!")
if guessfixed(0) != mylistkey: #by the way, this is still in the loop
print ("it did not quite work"),
The only way I know this is not working is because in the full script, I changed the key and guess to only have 4 combinations, so the key and the guess would have to overlap eventually, and it just kept going, supposedly trying 100 combos before I killed it. According to my tests, the guessfixed changes, and the key does not. And once again, thanks for reading this, and sorry if this is an off-topic question or is really obvious. I am 12, so I'm not that good at writing questions, but practice makes perfect!