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): 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
y = print ("[",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),", ",(random.randint(0, 9)),"]",sep="") return ymylistkey = [] # the random generated key 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() != mylistkey: if guessfixed() == mylistkey: print ("it worked!") if guessfixed != mylistkey: #by the way, this is still in the loop print ("it did not quite work"), and once again, thanks for reading this, and sorry if this is a off topic question or is really obvious. I am 12, so i'm not that good at writing questions, but practice makes perfect!
mercredi 11 décembre 2019
How do you compare the output of a function in python?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire