HOW TO USE TURTLE GRAPHICS IN PYTHON!

Hello, my name is Manuel and I run ManyProgramming™. Today I will be showing you how to use Turtle Graphics in Python. It is a pretty simple feature until you start getting to letters, and implementing it into a program. This blog will not be very long and will only introduce you to the basic and simplest features of Turtle Graphics like filling a shape, making a shape and lot’s of other things! We will also right words on turtle graphics. It’s pretty simple!

Firstly, I will show you how to make a simple shape, like a square. The idea is to use the curser (in Python) to draw the shape. You can also fill the shape and draw more complex shapes like circles and such.

>>> import turtle as t
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)

Now, you may think I’m a bit strange but if you were to type this into Python, then Turtle Graphics will automatically open and will start drawing by every line of code you say. When I write ‘import turtle as t’ at the beginning, the ‘t’ is only the nickname and can be anything as long as it doesn’t have a space and, in my opinion, is short because if it’s long, then what’s the point of giving it a nickname. However, if you do give it a nickname then you have to use the nickname before you the commands; e.g. my nickname is t so I do t.forward. If me nickname was lok, then I would have to do lok.forward because it follows what my nickname is. If you don’t want to have a nickname, then you can just write ‘import turtle’ and then you will have to write turtle.forward instead of an optional nickname!

Now, you can go in any direction. The options are ‘forward’, ‘right’, ‘left’ and ‘backward’ for moving the curser and manually drawing the shapes. Now you have a huge amount of different codes in Turtle Graphics and if you’de like to see all of them then Click Here!

Next up, we will be making circles and other shapes that aren’t as easy to make with a cursor. Note: If you would like to make an equilatorial triangle, all you have to do is go left(60) / right(60) and the length has to be the same! We will also be filling up the shape.

>>> import turtle as t
>>> t.color('red')
>>> t.begin_fill()
>>> t.circle(100)
>>> t.end_fill()

Now we will get a circle with the radius of 100 and it will be filled with red. If anything is wrong or if there is anything you don’t understand then email: programmingmany@gmail.com. You can change the size of the circle by changing the number after ‘t.circle’. I used red because I know it works but many colors work. If you are unsure whether a color works or not than contact me and I will figure it out for you. Note: Wherever you curser is facing on turtle graphics, the shape will always be on the left e.g. your curser if facing your right, then the shape will be above the curser & vice-versa.

If you want to clear your Turtle Graphics then do ‘.clear()’. Obviously you need to put the nickname you gave it or turtle before the dot as I explained above but other than that if will clear the whole turtle graphics.

Lastly, we will be writing on Turtle Graphics. This isn’t the most handy but might come in handy if you are trying to make a poster for example, or a sign, or anything that uses writing. It’s again, pretty simple. 

>>> import turtle as t
>>> t.color('orange')
>>> font=("Verdana", 15, 'normal', 'bold', 'italic', 'underline')
>>> t.write('ManyProgramming Blog')

Now there will be a piece of writing on the Turtle Graphics saying ManyProgramming Blog. It will be in orange because I told Python BEFORE to make it orange and it will be bolg, italic and underlined. You can also change the font. The default font is Arial but I changed it to Verdana. Yet again, if you have any concerns about fonts or anything else just contact me.

If you were to insert this into a piece of quiz, then you could have pictures on your python quiz. However, I don’t think you are able to use Turtle Graphics in most Python Frameworks when making a website so we might have to go over another one.

Thank you for reading my blog and I really hope it made your day. If you have any worries, for the last time, Contact me at: programmingmany@gmail.com. Also, get ready for my Christmas blog because it’s coming out on the 24th December at 7:00pm.If you would like to see my book reviews blog than Click Here!

INTRODUCTION TO LOOPS!

Hello, my name is Manuel and I run ManyProgramming™. Today we will be Introducing you to Loops. I hope you enjoy this blog.

Loops: Computers are great at doing boring tasks without complaining. The Programmers aren’t, but they are good at getting computers to do repetitive work for them; by using Loops. A loop runs the same block of code over and over again. There are several different types of loops.

For Loops: When you know how many times you want to run a block of code, you can use a ‘for loop’. In the example below, I am telling Python to print “Manuel’s Room – Keep Out!!!” Python knows how many times it should print that statement because I put the range (1, 8). At the beginning of the piece of code it says ‘for counter in range (1, 8)’. I have told you what the range is so now I will tell you what the ‘for counter’ means. The ‘for counter’ is the loop variable and means it is the counter of the loops. You either run it any number of times or for each element in a list or a dictionary.

>>> for counter in range (1, 8):
...    print('Manuel\'s Room - Keep Out!!!')
...
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!
Manuel's Room - Keep Out!!!

Range: In Python code, the word “range” followed by two numbers within brackets stands for “all the numbers from the first number to one less than the second number”. E.g. ‘range (1, 4)’ means the numbers 1, 2 & 3 – but not the fourth number. In my “Keep Out” program, range (1, 11) is the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 but not 11.

Escape Character (\): The Backslash in ‘Manuel \ ‘s room’ tells Python to ignore the apostrophe so that it doesn’t treat it as the quotation mark that closes the whole string. A backslash used like this  is called an Escape Character. It tell Python not to count the next character when working out if the line makes sense or contains errors.

While Loops: What happens if you don’t know how many times you want to repeat the code. Do you need a crystal ball or some other way of seeing into the future? No, it’s okay! You can use a while loop!

Loop Condition: A While Loop doesn’t have a loop variable that’s set to a range of values. Instead it has a loop Condition. This is a Boolean expression that can be either True or False. It’s a bit like a bouncer at a disco asking you if you’ve got a ticket. If you have one (True), head straight for the dance floor; if you don’t (False), the bouncer won’t let you in. In programming, if the loop condition isn’t True, you won’t get into the loop.

Balancing Act: In this example, I have written a program to keep track of how many of his troupe of acrobatic hippopotamuses have balanced on top of each other to make a tower. Read through the code and see if you can figure out how it works.

>>> hippos = 0
>>> answer = 'y'
>>> while answer == 'y'
        hippos = hippos + 1
        print(str(hippos) + ' balancing hippos!')
        answer = input('Add another hippo? (y/n)')

Loops inside Loops: Can the body of a loop have another loop within it? Yes! This is called a Nested Loop. It’s like Russian dolls, where each doll fits inside a larger doll. In a Nested Loop, an inner loop runs inside an outer loop. One Loop inside another: In this example I have changed my “Keep Out” program to a “Three Cheers” program that prints “Hip, Hip Hooray!” three times. Because each cheer includes the word “Hip” twice, I am using a Nested Loop to print it.

>>> for hooray_counter in range(1, 4):
        for hip_counter in range(1, 3):
            print('Hip')
        print('Hooray!')

Super Skills: We learnt about lists last Sunday and so now I will put loops into lists. I call it Super Skills because it is incredible what it can do. As you can see in the examples below I have written ‘x**2’ which is x to the power of 2. This means that if you switch the two with any other number, the power will be to whatever number you switched the two with.

>>> [x**2 for x in range(5)]
[0, 1, 4, 9, 16]

The Next example I will be showing is to repeat a certain word or number.  You always need to use square brackets [] and need to do this [‘anything_you_want’ for i in range(whatever_number_you_want)]. Here is the example I used:

>>> ["abc" for i in range(5)]
['abc', 'abc', 'abc', 'abc', 'abc']

Thank you very much for reading my blog and I hope you enjoyed it; I hope it made your day. If you would like to see my Book Reviews blog then Click Here!

INTRODUCTION TO LISTS AND DICTIONARIES!

Hello, my name is Manuel and I run ManyProgramming™. Today I will be introducing lists and Dictionaries to you. Make sure to stay tuned every Friday/Saturday so that you can enjoy the full tutorial.

Lists: Are collections of single values. Each element can be anything; integers, strings, floats or other objects; they need to be separated with a comma. I put some examples below

>>> this_is_a_list=[1,3,'Manuel',6,"Daniel"]
>>> this_is_a_list
[1, 3, 'Manuel', 6, 'Daniel']
>>> this_is_a_list[0]
1
>>> this_is_a_list[2]
'Manuel'
>>> this_is_a_list[4]
'Daniel'

To getout one of the elements, the square brackets [] with the number of the element inside. The counting starts with 0 and ends with the total number minus one. The total number of the elements can be obtained with the function ‘len(listname)’. 

Lists can even be cut or sliced. You need to use the square brackets [].The slicing is separated by the double colons; as you can see in the example below. 

>>> this_is_a_list
[1, 3, 'Manuel', 6, 'Daniel']
>>> this_is_a_list[0:2]
[1, 3]
>>> newlist=this_is_a_list[1:3]
>>> newlist
[3, 'Manuel']
>>> li=list(range(10))
>>> li
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> li[::2]
[0, 2, 4, 6, 8]
>>> li[::3]
[0, 3, 6, 9]
>>> li[::-1]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> li*2
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> li+li
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

As you can tell, I have made three lists (‘this_is_a_list’, ‘this_is_another_list’ & ‘li’) and have done calculations with the lists. You can call the lists anything other than the reserve words. If you want to know all of them send me an email (programmingmany@gmail.com) and I will send you how to get the reserve words for your version of Python. Lists can be multiplied (*) and added (+) but not divided (/) or taken away (-). You are also able to see different parts of the list as I have just showen you. You are able to have numbers, letters, or words.

 

Dictionaries: Are lists with an explanation or a value. In Python it is called a key and a value. Just like a physical dictionary. The key (the word that is being explained) has to be unique. It cannot be the same or it will be overwritten as you will see at the bottom of the examples. However, the value (the explanation or meaning of the key) can be the same.

>>> d={"Auto":"Car","Haus":"House, building","A":3}
>>> d
{'Auto': 'Car', 'Haus': 'House, building', 'A': 3}
>>> d["Auto"]
'Car'
>>> d["Auto"]
'Car'
>>> d["auto"]              # This is a misspelling
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'auto'
>>> d.keys()
dict_keys(['Auto', 'Haus', 'A'])
>>> d.values()
dict_values(['Car', 'House, building', 3])
>>> dd={'a':2,'b':4,'a':6}        # Duplicated keys 'a'
>>> dd
{'a': 6, 'b': 4}

You can also merge dictionaries. This is how; ‘Name_of_the_Dictionary.update (Name_of_the_dictionary_you_want_to_merge)’ If you do this in Python all the keys & values from the dictionary you put in brackets will be put into the the dictionary you put before the ‘.update’; making only one dictionary with all the entries (an entry consists of keys & values.

Thank You very much for reading my blog. Every view helps me a lot. This blog was done by Manuel & Daniel Kolb. I hope you continue reading my blogs every Friday! If you would like to see my book reviews blog than Click Here!

INTRODUCTION TO FUNCTIONS AND ‘IF’ CLAUSES!

Hello, my name is Manuel and I run ManyProgramming™. Today I will be introducing ‘functions’ and ‘if’ clauses to you. I hope you enjoy this blog! 

What are Functions? Functions are handy collections of code that can be re-used by calling the name of it! To define a variable you need to use ‘def’.

>>> def question_add(x=3,y=8):

             s = "What is " + str(x) + " + " + str(y) + "? "

             ans = input(s)

             if int(ans) == x + y:

                            print("correct!")

             else:

                            print("Wrong wrong wrong!")
How can you use this function?
>>> question_add()
What is 3 + 8? 11
correct!

>>> question_add(5,10)
What is 5 + 10? 14
Wrong wrong wrong!
If you run this function than you will see that it asks you to add 2 numbers. If the brackets are empty it will use ‘3’ & ‘8’ because I have pre-defined it. However, if you put two numbers inside of the brackets after ‘question_add, than the question will ask whatever 2 numbers you used.If you get the answer correct than it will say “correct!” However if you get it wrong, than it will say “Wrong wrong wrong!”. These are the very basics of my first project: Programming a learning website! We will need to use these in the website which we make.
Functions can return a value:
>>> def anything_you_want(x):

    return x * 2 + 5




>>> anything_you_want(3)

11

>>> y = anything_you_want(4)

>>> y

13
Now, what I have learnt about indents is that they always have to be the same size e.g. if you use 2 spaces than you have to continue using 2 spaces. You can change it if you are talking about a different function but when using the same function than you need to use the same number of indents every time. Now consider this example:
>>> def test()
   print('lolol')
print('lol')

>>> test()
lolol
Ok, so if you are wondering why it only printed ‘lolol’ instead of ‘lolollol’ is because after ‘def test()’ the print line had 3 indents and then the bottom line had 0 indents. Python thinks that the definition is finished if the indent number is not the same! WARNING: You will get an error if you do this!
Python has a number of built-in functions that you can use in your code. These are helpful tools that let you do lots of tasks, from imputting information and showing messages on the screen to converting one type of data into another. You’ve already used some of Pythons built-in functions such as “print ()” and “input ()”. Have a look at these examples. Why not try them out in a shell.
Now, let’s talk about ‘if’ clauses. They can help you to make decisions! For Example:
>>> quest = input('Do you speak German? y/n ')
Do you speak German? y/n N
>>> def question():
...     quest = input('Do you speak German? y/n ')
...     if quest.upper() == 'Y':
...         print('Guten Tag')
...     elif quest.upper() == 'N':
...         print('Buon Giorno')
...     else:
...         print('Please type Y/N')
...
>>> question()
Do you speak German? y/n n
Buon Giorno
>>> question()
Do you speak German? y/n N
Buon Giorno
>>> question()
Do you speak German? y/n a
Please type Y/N

Now as you can tell I have just defined what ‘question’ is. I said that if they answer ‘y/Y’ which stands for yes it will print Guten Tag. Otherwise if they answer ANYTHING else (gggdsajgyh, yy, nodh, nopped), it can literally be anything, than it will answer ‘LOSER!!!!!!!!!!!!!!!!!!!!!!’.

Now with the function name. You can have anything you want as the function name as long as there are no spaces. You can use an underscore _ to fill in for spaces. Alternatively use no spaces at all e.g. Anything you want (Not-Allowed) e.g. Anything_you_want (Allowed) Now one word is also allowed e.g. anythingyouwant. You are also not allowed to have a number at the beginning on the function name e.g. 1xx. If the number is at the end or in the middle then that it is alright!
Thank you for reading my blog and I hope you stay tuned every Friday for new Python blogs. I hope you enjoyed reading my blog and I hope it helps you. If you enjoy reading and would like to see my reading blog then Click Here!

INTRODUCTION TO “int”, “float” & “str” IN PYTHON!

Good Afternoon. My name is Manuel and I run ManyProgramming™. Today I have got a start-up on what “int”, “float” and “str” is on Python. I hope you enjoy and continue following me!

“int” standing for Integer is a whole number! E.g. 1, 2, 3, 4,000…                                We  You usually use them as variables e.g. x=1, y=100, z=1000…

If, on Python, you do this:

>>> x=1

>>> type (x)

<class ‘int’>

>>> print (x)

1

You can even use Python as a pocket calculator very easily. For Example,

>>> 3*x-1

2

Next, I will define more variables.

>>> a=2

>>> b=3

>>> c=4

Now I have defined 4 Variables as Integers. “x=1”, “a=2”, “b=3” & “c=4”.

>>> a*b*c*x-a-b-c-x

18

 This can be used very flexibly and some people even use it as a calculator. This is a bit random but you are able just to do this:

>>> 195*195

WARNING! When using multiply than you have to use * instead of x. Same with division. You need to use / instead of the normal one you use on normal calculators!

This, with the colours work on IDLE versions of Python, when the background is white. The “x=1” doesn’t have to be a 1 but I did it because I have just written on integers!

“float” standing for Floating Number is a decimal number! E.g. 1.5, 1.6…

Similar to the string and the integers the floating number is often used in a variable e.g. x=1.5, y=1.6…

If in Python you do this:

>>> z=1.5

>>> type (z)

<class ‘float’>

“str” standing for String is a sequence of characters! E.g. Hello, World, Mum… 

We usually use them when defining worded meanings

E.g. x=”Hello World”, y=”my mum”…

>>> y=”Hello World”

>>> type (y)

<class ‘str’>

You can also put numbers as a string! e.g. “1000” is a string but 1000 without the inverted commas is an Integer. Now follow along as I teach you about how to change a string to an Integers. 

>>> g=”12345″

This is a String.

>>> h=12345

This is an Integer. I will now overwrite ‘h’ to make it a string.

>>> h=”67890″

Now you are able to add strings. The two strings will extend instead of adding numerically! e.g. 123+456 (if it is a string) will be 123456. 123+456 (if it is an Integer) will be 579!

>>> g+h

1234567890

>>> int (g) + int (h)

80235

Yes, I know, you might look a little surprised but the concept is very simple. I have defined ‘g’ & ‘h’ as strings but here I changed them, only for this time, to an integer.

The ‘z’ and the ‘1.5’ can be replaced. The ‘z’ can be replaced by any letter but be careful because if the letter is the same as one you have used before. You could do it on purpose or you might accidentally do it. The ‘1.5’ can be replaced by using any other number; if you want a floating number than you should take a decimal number!

To change the class please follow what I will do next!

>>> x=”1″                         This is an Integer (int)

>>> x=”Hello World”         This is a String (str)

>>> x=”1.5″                       This is a Floating Number (float)

Just change the variable to the chosen class by using the top three to adjust it!

You can even add strings!

>>> a=”abc”
>>> b=”xyz”
>>> a+b
‘abcxyz’

Thank you very much for listening to my first proper blog on Python. Hope you tune in for next weeks Friday! If you would like to see my Book Reviews blog than Click Here!

INTRODUCTION TO MANY-PROGRAMMING & PYTHON!

Good Morning. My name is Manuel and I run ManyProgramming™. This is my first blog. I have designed my Blogs to be different projects on Python. First I want to start to create a website to help learning different subjects. Later I plan to build robots, and other things that are fun. I will describe it in a series of blogs posted every Friday. This will break my big projects into small diverse parts. Please ask me any questions if my descriptions are not clear to youI am learning too while writing about it!

Firstly, if you have Python than you can skip this paragraph but if you don’t have Python or you are not sure than you can download it for free at https://www.python.org/downloads/. There are three main operating systems which you can get Python on: Linux, Windows and the Apple systems. If you have Linux, then you probably have Python but check if you have it. You should go to start menu to check if you have Python. If you have Windows than you should ask Cortana (Windows’ AI help assistant). If you have an Apple laptop that you can ask Siri (Apple’s AI help assistant). If after your check you do not have it, I know I repeated it, then go to https://www.python.org/downloads/. It doesn’t matter much which version of Python you install; I am using Python version 3.6 currently but 2.7 still works. 

 You can either type Python onto a command prompt or you can open IDLE. At the moment I am using IDLE because I find it much simpler to set up and command prompt is much older. Additionally you would need to have a text editor. It can be very simple if you want. I am using notepad in Windows at the moment but I am planning to try others in the future.

What is Python: Python is one of the most popular programming languages because it very simple to learn but on the other hand very powerful and flexible. What I like is that I can type in the commands and just test if it works.

Next week I will be writing about Integers, Strings and Floating Numbers. The following week I will be writing about Functions. The week after that I will be writing about Lists and Dictionaries. And then I will put everything together into a little program. After I have the program together I will try to put it into a webpage.

ManyProgramming aims to help this generation improve their life quality instead of just spending money and time on fortnite for their whole lives. We aim to bring people into the arts of engineering because as AI comes, so should our programming skills. Soon robots could even be doctors!

I got all my information from Python Website. It is free to use and if you need any further information contact programmingmany@gmail.com! Thank you for joining me on my first blog and I hope you enjoy your day. If you want to see my book reviews blog than Click Here!