# Python Help

**URL:** <https://forum.makecode.com/t/python-help/6899>\
**Category:** Help\
**Created:** [March 22, 2021, 2:36am UTC](https://forum.makecode.com/t/python-help/6899 "2021-03-22T02:36:01Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [March 22, 2021, 2:36am UTC](https://forum.makecode.com/t/python-help/6899/1 "2021-03-22T02:36:01Z")

</div>

I need help with non-makecode python. I’m trying to put the number of tries it took to get the number. Help?

 ![Screenshot 2021-03-21 141230](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4e13e9fa01bca15035eda5ae569f6fb0781f900c.png)

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [March 22, 2021, 4:22am UTC](https://forum.makecode.com/t/python-help/6899/2 "2021-03-22T04:22:17Z")

</div>

@UnsignedArduino?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [March 22, 2021, 3:12pm UTC](https://forum.makecode.com/t/python-help/6899/3 "2021-03-22T15:12:52Z")

</div>

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

```auto
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 \>:)

```auto
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

```

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [March 22, 2021, 4:19pm UTC](https://forum.makecode.com/t/python-help/6899/4 "2021-03-22T16:19:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [March 22, 2021, 4:30pm UTC](https://forum.makecode.com/t/python-help/6899/5 "2021-03-22T16:30:05Z")

</div>

Ah it takes time but you will learn - if you ever need help just post here!

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [March 22, 2021, 4:51pm UTC](https://forum.makecode.com/t/python-help/6899/6 "2021-03-22T16:51:39Z")

</div>

OK!  
why do you have to have the f in front of the Quotations?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [March 22, 2021, 5:17pm UTC](https://forum.makecode.com/t/python-help/6899/7 "2021-03-22T17:17:24Z")

</div>

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:

```auto
>>> x = 0
>>> print(f"The value of x is {x}")

```

will print:

```nohighlight
The value of x is 0

```

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [March 22, 2021, 5:26pm UTC](https://forum.makecode.com/t/python-help/6899/8 "2021-03-22T17:26:51Z")

</div>

Ohhh, thanks so much!!

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [May 28, 2021, 5:13pm UTC](https://forum.makecode.com/t/python-help/6899/9 "2021-05-28T17:13:15Z")

</div>

I know this is more like minecraft, but would it be possible to make a minecraft mod using python @UnsignedArduino ?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [May 28, 2021, 8:52pm UTC](https://forum.makecode.com/t/python-help/6899/10 "2021-05-28T20:52:08Z")

</div>

You can use MakeCode for Minecraft:

> **[Microsoft MakeCode for Minecraft](https://minecraft.makecode.com/)**
>
> Minecraft Code Editor using Blocks or JavaScript

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:

> **[zhuowei/RaspberryJuice](https://github.com/zhuowei/RaspberryJuice)**
>
> A plugin for Bukkit implementing the Minecraft Pi API - zhuowei/RaspberryJuice

But it wouldn’t be like a mod - it’s pretty limited and it can’t accept chat commands.

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [May 28, 2021, 8:54pm UTC](https://forum.makecode.com/t/python-help/6899/11 "2021-05-28T20:54:02Z")

</div>

I mean like actual python for like [forge] minecraft?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [May 28, 2021, 9:37pm UTC](https://forum.makecode.com/t/python-help/6899/12 "2021-05-28T21:37:46Z")

</div>

Then I don’t know, sorry ☹

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [May 28, 2021, 11:55pm UTC](https://forum.makecode.com/t/python-help/6899/13 "2021-05-28T23:55:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [May 29, 2021, 4:31am UTC](https://forum.makecode.com/t/python-help/6899/14 "2021-05-29T04:31:09Z")

</div>

Well…if someone wrote an bridge between the Java APIs and Python you could write a mod in Python XD

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [May 29, 2021, 4:31am UTC](https://forum.makecode.com/t/python-help/6899/15 "2021-05-29T04:31:28Z")

</div>

ah, thanks for the help

---

<div class="post-metadata">

**Author:** ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)\
**Post date:** [June 1, 2021, 2:48am UTC](https://forum.makecode.com/t/python-help/6899/16 "2021-06-01T02:48:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![purna079](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/purna079/32/4018_2.png) [@purna079](https://forum.makecode.com/u/purna079)\
**Post date:** [June 6, 2021, 5:16pm UTC](https://forum.makecode.com/t/python-help/6899/17 "2021-06-06T17:16:50Z")

</div>

Now I’m working with Java. It is Much harder! T\_T(jk);

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [June 6, 2021, 8:51pm UTC](https://forum.makecode.com/t/python-help/6899/18 "2021-06-06T20:51:31Z")

</div>

Good luck! (I’ll be learning Java next year too! ~~We’ll suffer together~~ )
