You are on page 1of 1

Features Blog Pricing Teams Pro Teams for Education Careers Sign Up Log In

This post is read-only. Explore Repls and connect with other creators on Community. View Community

The info in this post might be out of date, check out our docs instead. View docs

1
Hey! I'm a little lost with this can someone help me please?

LeviAckerman8

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
2 years ago

@LeviAckerman8/Mastermind
Open on Replit
A Python repl by LeviAckerman8

Hide files Like Run 170

1 from random import shuffle


Files 2 Numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
3 def eliminate(how_many):
main.py
4 shuffle(Numbers)
5 for x in range(how_many):
6 Numbers.pop(-1)
7 return Numbers
8 Numbers = eliminate(5)
9 Answer = input("Please enter 4 digits to try and guess the secret code ")
10 Wrong = 0
11 while Answer != Numbers:
12 Wrong = (int)(Wrong) + 1
13 print("Sorry try again. You got " + (str)(Wrong) + " wrong")

Answered by RYANTADIPARTHI View Answer

Voters

LeviAckerman8

Comments Top New

RYANTADIPARTHI
4
what have you tried first?
2 years ago

LeviAckerman8
1
@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?
2 years ago

RYANTADIPARTHI
1
@LeviAckerman8 we aren't supposed to give code, but I'll explain.

import random module, and use randint to generate 1, 9


make an input
check if the user answered by using input == variable .
then give the var to see how many tries
put all this in a function.

Done!
2 years ago

LeviAckerman8
1
@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)
2 years ago

Coder100
1
not exactly, you have to generate 4 random numbers, but remember they can repeat @LeviAckerman8
2 years ago

RYANTADIPARTHI
1
@LeviAckerman8 ok, that's good for now. more?
2 years ago

LeviAckerman8
1
@Coder100 It worked for me?
2 years ago

Coder100
1
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
2 years ago

Load more

legal replit features handy links social media learn to code

terms of service mobile app IDE create a repl facebook 100 Days of Code
privacy blog multiplayer docs twitter
subprocessors about community ask for help instagram
DPA careers teams status page discord
US student DPA teams for education hosting python packages
student privacy pricing ghostwriter import from glitch
bounties import from heroku
AI comparison
brand kit

languages

Clojure Bloop Python F# Crystal TypeScript Pyxel


Haskell Unlambda Node.js HTML, CSS, JS Julia Pygame Raku
Kotlin CoffeeScript JavaScript Rust Elixir Love2D Scala (beta)
QBasic Scheme Deno (beta) Swift Nim Emacs Lisp (Elisp) Nix (beta)
Forth APL Golang Python (with Turtle) Dart PHP Web Server Kaboom (beta)
LOLCODE Lua C++ Basic (beta) Reason Node.js SQLite
BrainF Ruby C R Tcl Java
Emoticon Roy C# Bash Erlang PHP CLI

Copyright © 2023 Replit, Inc. All rights reserved.

You might also like