2022-01-23 19:34:38

IDK what the heck is wrong, please help.
here's the code.
##gues the number, by pax
import random
def randguess():
##because I can't put the indent before the variable, I'll use pass for that.
pass
number=random.randint(0,100)
guess=input("your guess?")
chances=10

if(guess==number):
   print("you won 100000000 dollars!")
else:
print("nope, that's not it!")
chances-1
while(chances>0):
randguess()
else:
print("you lost")

meow meow.

2022-01-23 19:50:51

Please put more effort than "Idk what the heck is wrong". What error are you getting, what have you tried, ETC. Also, I can't see any indentation. I'm not sure if the forum broke it or you didn't put it in.

2022-01-23 19:54:31 (edited by ashleygrobler04 2022-01-23 19:56:04)

Hi there. I've rewrote your code, please try it out.
Before I post it, Just a few issues...
You want to make sure the player can input the number while they've got enough guesses, else the game might not work as expected.
So putting the input in the while loop solves the problem. What exactly was your issue any ways?

Edit: Oh and lastly, make sure you convert the user's input to an int as that's what you'd want to compare it with, a number (random number generated from random.randint is going to be an int. Just saying as you might face some issues in the future.Here is the code:

import random
def main():
    number=random.randint(0,100)
    chanses=10
    while chanses>0:
        choice=int(input("Please enter a number from 0 to 100"))
        if choice==number:
            print ("You guessed it!")
        else:
            chanses-=1
            print (f"You've got {chanses} chanses left. Please try again.")
    print (f"The number the computer thought of was {number}")

if __name__=="__main__":
    main()
best regards
never give up on what ever you are doing.

2022-01-23 20:15:58

question, why you are using print like that, with the letter f before the quotes?
            print (f"You've got {chanses} chanses left. Please try again.")

meow meow.

2022-01-23 20:26:34

In python it's called a format string if I am not mistaken. It just makes the code a little more readable than using concattenation.

best regards
never give up on what ever you are doing.

2022-01-23 20:34:01 (edited by PatrykK 2022-01-23 20:40:07)

there's stil the issue, I tried to make it work fully, because there was an issue if player won, he was stil in the game.
and the fixes makes the while line "invalid syntax"
code that I made is below,
##guess the number, by pax and some help of ashleygrobler04
import random
def main():
    number=random.randint(0,100)
    chances=10
    while chances>0:
        choice=int(input("Please enter a number from 0 to 100"))
        if choice==number:
            print ("You guessed it!")
exit
else:
            chances-=1
            print ("You've got {chances} chances left. Please try again.")
    print ("it' was {number}")

if __name__=="__main__":
    main()

meow meow.

2022-01-23 20:46:31

Dude I don't understand what you want to do... let the while loop then check if the choices are greater than 1.

best regards
never give up on what ever you are doing.

2022-01-23 20:48:00

yeah, but if player won the game, it should output something then wait for pressing enter then close

meow meow.

2022-01-23 21:12:46 (edited by magurp244 2022-01-23 21:14:22)

An input box with a loop break would work:

##guess the number, by pax and some help of ashleygrobler04
import random

def main():
    number=random.randint(0,100)
    chances=10
    while chances>0:
        choice=int(input("Please enter a number from 0 to 100"))
        if choice==number:
            print ("You guessed it!")
            ##chances = 0
            break
        else:
            chances-=1
            print ("You've got {chances} chances left. Please try again.")
    input("it' was {number}")

if __name__=="__main__":
    main()
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2022-01-23 21:31:31

@magurp244 you will also get listed in readme, when the game will work.
I'm planning to add sounds, probably language support, then a configuration for the game.
but, for now, we have what we have, and I will work on inplementation of stuf.
first version(with sounds), will be soon

meow meow.

2022-01-23 22:16:46

Lol you're not seriously going to release this, are you? It's hardly breaking new ground. Though I suppose you could put it in the devs room if nothing else.

2022-01-23 22:26:20

I mean, I could be a small time waster.

meow meow.

2022-01-23 22:56:04

Heh, heh heh. I mean you have to start somewhere, but for the love of god don't release a guess the number game with literally no extra gimmicks or anything to make it special.

You ain't done nothin' if you ain't been cancelled
_____
I'm working on a playthrough series of the space 4X game Aurora4x. Find it here

2022-01-23 23:44:35

@PatrykK, for the future, please put some effort in describing what kind of error you're getting instead of saying IDK what's wrong. Also, please put your code in brackets, you can see an example of that in the BBCode link.

2022-01-24 03:24:26 (edited by stewie 2022-01-24 03:25:14)

I suspect the problem you are having is with your indentation. In the most recent example you posted, the exit line had no spaces before it and the else also didn't. The number of spaces needs to match the current block you're in. For example, an if statement needs the following code to be executed if the condition is true to be indented one more level (4 spaces in this case seems to be the number you're using for each level). Try indenting exit by 12 spaces and else by 8.

Also exit on its own does nothing (it is a function to exit a python app, not a single word statement). Either change it to exit() or change it to break instead. Break is probably the better statement to use, it will just exit the loop even though the loop condition is still true. If you use exit(), the python app will immediately exit and not perform the print statement after the loop.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.