I need help with non-makecode python. I’m trying to put the number of tries it took to get the number. Help?
Well, first this:
- A MakeCode Arcade forum, so not really relevant but ok sure
- And it would be easier to post the text, not an image of the text so we don’t have to type it all out and we can copy and paste
First, I’ve formatted a bit to my liking sorry I’m picky
from random import randint
correctNumber = randint(0, 100)
while True:
guessedNumber = int(input("Guess the number: (0 - 100) "))
if guessedNumber == correctNumber:
print("Correct!")
print("Good job!")
break
elif guessedNumber < correctNumber:
print("Too low!")
elif guessedNumber > correctNumber:
print("Too high!")
print("You win!!!")
If you want to count how many guesses it took the player, you need a variable that starts at 0 and increments every time the player makes a guess. Then display it at the end.
Try to figure it out yourself but if you are stuck here is the answer behind the spoiler >:)
from random import randint
correctNumber = randint(0, 100)
guesses = 0 # Define a variable to count the number of guesses
while True:
guessedNumber = int(input("Guess the number: (0 - 100) "))
guesses += 1 # Increment every time the player guesses
if guessedNumber == correctNumber:
print("Correct!")
print("Good job!")
break
elif guessedNumber < correctNumber:
print("Too low!")
elif guessedNumber > correctNumber:
print("Too high!")
# The f-string formatting was introduced in Python 3.6 - if you are on a older version you can do something like this:
# (Although I highly recommend upgrade to 3.9 if you aren't already - many new fun features are being added all the time!)
# print("You win!!! It took you {0} guess(es)".format(guesses))
# Otherwise stick to f-strings as it's more "Pythonic"
print(f"You win!!! It took you {guesses} guess(es)")
# Or if the above is too confusing, you can do something like this:
# print("You win!!! It took you " + str(guesses) + " guess(es)")
# Note that since guesses is a number, you can not add it to a string without first turning the number into a string
Thank you soooo much! I am new to python and It’s hard. thank you!
Edit: Variables are tricky like that! why do you have to have the f in front of the Quotations?
Ah it takes time but you will learn - if you ever need help just post here!
OK!
why do you have to have the f in front of the Quotations?
Search up f-strings, they are really cool. Basically if you put f
in from of a string then anything within brackets ({}
) will be considered a statement which will be converted automatically to a string before being inserted there.
So something like this:
>>> x = 0
>>> print(f"The value of x is {x}")
will print:
The value of x is 0
Ohhh, thanks so much!!
I know this is more like minecraft, but would it be possible to make a minecraft mod using python @UnsignedArduino ?
You can use MakeCode for Minecraft:
But it only works if you use Minecraft Education Edition. But it can accept chat commands and do lots of fun stuff like spawn mobs, set blocks.
For Minecraft Java Edition, you can use the Raspberry Pi Juice plugin:
But it wouldn’t be like a mod - it’s pretty limited and it can’t accept chat commands.
I mean like actual python for like [forge] minecraft?
Then I don’t know, sorry
No. Mods are strictly written with either java language or c++. Also, as I had said before, you’re better off using a mod creator like mCreator
Well…if someone wrote an bridge between the Java APIs and Python you could write a mod in Python XD
ah, thanks for the help
Well, there already probably are, but still, it would be written in java (for java) or c++ (for bedrock) at its deepest. At least mCreator has a block workspace environment along with text based.
Now I’m working with Java. It is Much harder! T_T(jk);
Good luck! (I’ll be learning Java next year too! We’ll suffer together)