Python tutorials #1 – basic calculator

This is the first of my Python tutorials! Python is a programming language but unlike C++ and Java, is easier to learn but can still be used to create amazing programs such as web browsers, calculators, word processors, and more. But unlike Scratch, a GUI used to make games and other projects aimed at beginners and young children, you still must master Python to create amazing applications using it.

So, here’s my first tutorial: a basic calculator that can be used to add, subtract, multiply, and divide two numbers. Unlike the calculator app preloaded on your PC or phone however, it is CLI based so you won’t have a friendly GUI calculator but rather one where you type two numbers, what you want to do with them, then get the result printed to the screen.

This guide assumes that you are using the newer Python 3.x. The code may work on Python 2.x, but has not been tested, so if you need to stick to Python 2.x for some reason, you may have to make adaptations to the code for it to work properly.

Fire up your Python IDE (such as IDLE3 or Geany) and enter in the following code:


first_number = input("Enter in first number: ")
second_number = input("Enter in second number: ")
print(int(first_number) + int(second_number))

This basic block of code will ask you to enter in the first number, then store that first number, then enter the second number, store that second number, and then show the answer. The int around the variables converts them into intergers so they can be added together as numbers, not as characters. Without this 5 + 10 would equal 510, not 15.

This, however, is a little restricted. You can only add the two numbers, not subtract, multiply, or divide. Asking the user for what they want to do with the two numbers and then doing that expands the calculator’s functionality. For example:


first_number = input("Enter in first number: ")
second_number = input("Enter in second number: ")
option_choice = input("Add, subtract, multiply, or divide? ")
if 'dd' in option_choice:
print(int(first_number) + int(second_number))
elif 'ubtract' in option_choice:
print(int(first_number) - int(second_number))
elif 'ultiply' in option_choice:
print(int(first_number) * int(second_number))
elif 'ivide' in option_choice:
print(int(first_number) / int(second_number))

We are not doing if statements to see if, for example, option_choice equals ‘add’ as Python is case sensitive in this area. Checking for ‘dd’ (end of ‘add’) ensures that the program will work regardless of whether A is capital or not.

So there you have it! A basic calculator made in Python. Currently lacks support for decimals however, so if you try entering decimals the program will error out. This guide is aimed at beginners, so this calculator will likely be expanded on in a future guide. Enjoy!

-Chas 😎

One lovely blog award – who are my favourite bloggers?

This challenge has spread across the internet like fire (I didn’t create this challenge) so I have decided to do one. Basically, I have to tell you 7 things about my character. And up to 15 bloggers I enjoy. I have over 40 followers, but as there are limits (a few don’t have blogs) and you can only do up to 15. I am sorry if I do not include you!

So, here are the 7 things about me!

1. I think about my web browser project, ECG SeaSurf , for a lot of my time. I love it because the world wide web is a big place, and making software that allows people to browse such a great thing makes me feel special.

2. I do not try to block the spotlight from other developers as I love seeing what others have produced too, and I love getting inspired.

3. I love playing video games because they are extremely fun, and it feels like I am in the game (no VR here!). They also take stress away.

4. I love writing stories, to entertain people. I am writing a story called Sir Wolf’s Castle, about Minecraft wolves and a villan called Sir Bum-Smacker.

5. I love looking at over blogs and leaving feedback and liking posts because I don’t want to look selfish.

6. I love ketchup. It is an awesome sauce.

7. There are lots of other things I love but don’t blog about: Star Wars and Legends of Chima, for example.

Now, here are my favourite bloggers: I DO NOT ACCEPT RESPONSIBILITY FOR LINK CONTENT CHANGING

1. Codeinfig:

An author of a coding language called Fig, a coding enthusiast, and much more. Check out his blog at codeinfig.wordpress.com!

2. Jacque:

If you want to go beyond my app-making service (I would recommend trying it first and requesting a removal if you don’t like it), then Jacque is the person for you. He can even get your app published to the Play Store (I didn’t ask for an app because I can make one myself).

Check out his blog at themarvelousmind.com

3.  ARJ

If you want a guide to coding and you want to be a pro, then ARJ’s blog “A bit of everything – copy” is the place for you. He has another blog, pythongr.wordpress.com, which is worth checking out too.

Find his main blog at abdurrahmaanjanhangeer.wordpress.com

4. Daniel He hetianding

A Minecraft enthusiast, this blogger creates maps and then publishes them.

Find his blog at worldofmanyworlds.wordpress.com.

5. LZH

A real tech enthusiast, admin of a website called TechCentral which contains everything tech.

Leave a comment or like at limzhenghong.wordpress.com

6. AntonioWestley

A master blogger, who loves posting about sites he recommends.

Check out his active site at alltheeabove.wordpress.com.

Check out his inactive site at antoniowestley.wordpress.com

7. antepher

A real ESP8266 and Arduino enthusiast, as well as Python Expert, antepher maintains a blog called techtutorialsx.

Like and comment on his blog at techtutorialsx.wordpress.com!

8. Paul Sinha

One of my first followers, Paul Sinha appears on the Chase and is really funny.

Check out his blog at sinhaha.com

9. Old and New Reviews

Reviewing and playing video games, I enjoy reading this blog.

Follow the blog at oldandnewreviews.com!

10. Is there any blog you recommend?

I can’t think of a tenth, but I want to reach 10, so if you recommend a blog, plz leave  a comment.

PS: The rules (I have forgotten the URL to the original creator’s blog) also mention that you should post about being chosen. So, thank you codeinfig for choosing me! SO, remember that!

Epic Chas Gamer 😀

 

 

 

MCPE Multiplayer with Minecraft Pi Edition

The Pi Edition is based on an old version of MCPE, isn’t it. Can you play multiplayer between the two?

If you download a 0.6.1 APK you can play multiplayer by opening a world on the Pi Edition and pressing Join Game on the Pocket Edition. Amazing!

 

 

 

TNT Trail!

Today on Minecraft Pi Edition I programmed a TNT trail. You walk around after the code has been ran, and TNT appears! Ignite some! Please note that not all the TNT is ignitable but the unignitable TNT still blows up when ignitable TNT blows up.

Copy and paste the code into Geany (or your preferred Python environment) and run it. Make sure you are on a world on Minecraft and hit the TNT that appears each step. Press CTRL +C in your Python environment to stop the TNT trail.

The code is here:

from mcpi.minecraft import Minecraft
from time import sleep

mc = Minecraft.create()
x, y, z = mc.player.getPos() # player position (x, y, z)
this_block = mc.getBlock(x, y, z) # block ID
print(this_block)
tnt = 46

while True:
x, y, z = mc.player.getPos() # player position (x, y, z)
block_beneath = mc.getBlock(x, y-1, z) # block ID

if block_beneath == tnt:
mc.setBlock(x, y, z, tnt, 1)
sleep(0.1)
else:
mc.setBlock(x, y-1, z, tnt)
Enjoy!

Epic Chas Gamer 🙂