anyone good at python???? how da hecc do i fix dis import comp_choice = random.randint (1, 3)
Do you have a pic?
uh yeah hang on
I think you would not import "comp_choice" since that is the variable you are initiating. Instead, you would want to import the module you are using for the random number generation. Is that called "random"? Thanks for the picture too!
maybe dont space out the =
isnt it to spaced out?
So, before defining comp_choice, you would want a line that reads "import random" so that the module is recognized. Then, "comp_choice = random.randint(1,3)" should work
Oh interesting. Did you try to run your code? And did an error message appear?
yep
Oh how about this. Instead of random.randint(1,3) try random.randrange(1,3) Just like they show here https://www.w3schools.com/python/gloss_python_random_number.asp#:~:text=Python%20does%20not%20have%20a%20random%28%29%20function%20to,display%20a%20random%20number%20between%201%20and%209%3A
TwT sorry for bothering you ik this is kinda annoying but it didnt work
Oh huh that is surprising! I'll do some more digging. In the meantime, do you think you could describe what happened when you tried to run your code?
yeah
this^
It's saying 'random' is not defined, which is strange since it's supposed to be a module built into Python. Just making sure, did you make sure to import random at the top of your code? Also, since you're using randrange, you'd want to use (1,4) instead of (1,3), since it would make a range going up to the second parameter, not including it
What does your new code look like, by the way? That might help us find out what's going on
I'm not seeing that "import random" statement. Even though random is built-in to python, you still need to import it for the code to recognize it. Try putting "import random" at the beginning and see if the results change at all
sorry wrong file here
Ok, it looks like the import statement is in the middle of your while-loop, which shouldn't be the case. So, "import" just lets the code know that you want to use something from a specific library or module; you only need to do it once, usually at the beginning of the code before anything else. Also, you would import the module (or the parts of it that you need), not the statement you're trying to execute. Instead of "import random.randrange(1,3)" inside the while loop, move "import random" to the beginning of the code and your statement would look like comp_choice = random.randrange(1,4)
apparently python hates me
Can you show me your current code and error message?
I see. Make sure to put your "import random" statement at the top of the code, since it doesn't look like you have that there
i did that like .2 seconds ago and it still didnt work
Interesting. Did the result change at all, even if it isn't what you wanted?
nope
Still the same error message and everything, huh? How odd. Do you mind if I take a look?
(Sorry, off to have dinner now; I'll make sure to take a look when I'm back)
sure ill put some more ss
Thank you! The error message makes the issue quite clear: "IndentationError: unindent does not match any outer indentation level" On line 26, it looks like the code isn't lined up properly. Adding another space or two at the beginning of the line to make it match up should solve that problem. Python just happens to be one of those languages where indentation does matter, as you can see
Also, don't forget to change random.randrange(1,3) to random.randrange(1,4). A range of (1,3) would go up to 3, but not include 3, while a range of (1,4) would include 1, 2, and 3, but not 4.
thx for helping with that problem but i now have another
Glad to help! If you've got another problem, I don't mind taking a look at that one as well. Let's see...
Oh that one is simple! It looks like you named your variable "choice" earlier in the code, but on that line you called it "choice_name" by mistake, so it's not recognized.
ah thanks
No prob. It often helps just to get another set of eyes on code. Working on these things for a long times tends to give us a form of "tunnel vision" XD
this is my first time working with this so i appreciate it
No problem. It's true that I've had a little more experience, but everyone has had their first time at some point. Maybe before too long you'll be helping people out just like this :) Anyway, I'm glad we were able to figure it out!
yeah thanks again for the help
Join our real-time social learning platform and learn together with your friends!