Hey! I'm a little lost with this can someone help me please?
Computer should generate 4 random numbers from 1 - 9 as the "Secret Code".
User should be prompted for their guess of those four numbers.
After they provide their full guess, the user is told how many are correct.
As long as the user does not get all four correct, they keep getting asked for their guess.
After the user finally gets all of them correct (yes - all four), they are congratulated and then told how many tries it took them.
Technical Requirements:
Use at least one list
Use at least one function with parameters
try this:
https://repl.it/@Coder100/working-repl-bruh-PoliteGoldenrodMemory#main.py
what happens is that you look at the amount correct by setting that to 0, and then you just check if each item matches in the generated array, but then if they do match, you just add correct by 1. Afterward, finally you do it again if the correct wasn't 4
what have you tried first?
@RYANTADIPARTHI Nothing. That's the thing, idk how to do it. I guess if I used a list at the beginning to generate four random numbers then I could use a while loop but how would I go about that?
@LeviAckerman8 we aren't supposed to give code, but I'll explain.
random
module, and userandint
to generate1, 9
input
input
==variable
.Done!
@RYANTADIPARTHI Ok so this is what I did for the code: from random import shuffle
Numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def eliminate(how_many):
shuffle(Numbers)
for x in range(how_many):
Numbers.pop(-1)
return Numbers
Numbers = eliminate(5)
not exactly, you have to generate 4 random numbers, but remember they can repeat @LeviAckerman8
@LeviAckerman8 ok, that's good for now. more?
@Coder100 It worked for me?