Initial Setup

https://www.python.org/downloads/release/python-374/

Download x86 - 64 web installer. Check the box for add to PATH.

https://sourceforge.net/projects/pyscripter/files/latest/download

Download and click next until you have the option to: Create desktop shortcut. Check the box and then finish the download.

Create a Folder where you would like to keep your Python Projects and name it “PyScript Projects”. Then add a new folder named “1a”.

Go to your command prompt and enter in “python” to see which version of python you are running. It should be the same as the one that you downloaded, or at least 3.X.X.

Time to Code

Now open up PyScripter (there should already be a shortcut on your desktop).

Near the bottom you will see >>> in the python interpreter. Click there and type your first line of code.

print("Hello World!")

print() is a built in function of Python. It takes a parameter in and outputs what the parameter was as a string.

Now try typing “Hello World!” straight into the interpreter.

>>> "Hello World!"
'Hello World!'

In python strings are outputted as ‘The String’. Therefore, you can utilize and interchangeably when typing a string. The most useful functionality that comes out of this is when a string you’re typing contains inside of it.

For example, type ‘“Hello World!”’ into the interpreter and then type “”Hello World!“” into the interpreter.

>>> '"Hello World!"'
'"Hello World!"'


>>> ""Hello World!""
  File "<interactive input>", line 1
    ""Hello World!""
          ^
SyntaxError: invalid syntax
>>> 

As you can see, it gives us a syntax error. This is because the “” are meant to contain a string, so when we have an opening and a closing and then text outside of the quotations, that are not a pre-existing variable, it will give us a syntax error.

Next we will talk more about varaibles, but first go ahead and play around with print() and Strings for a little bit and then try the challenge below.

Challenge 1

First, change the name at the top of the editor to challenge1, remove everything below the “—…” line and then save it as “challenge1” in your “PyScript Projects” folder.

Write your initials using a print statement. The challenge is that you need to have each letter of your initials made up of that same letter. Your string should be 10 letters tall and each letter should be 8 wide. Other than that each letter can look how ever you think it should. Example of what the output should be below but feel free to make the letters look how you wish, just keep it 10 tall by 8 wide/letter. Delete all of the code in the text editor, above the interpreter, that is already there, then write your code in the text editor and run it (the green |> in the top tool bar).

TIP:
if you are using a single print() statement you can use \n to make a new line after each row of your output. \ allows you to continue your code to the next line.

print("aaa \n" \
    + "aaa \n")


BBBBB     L
B   BB    L
B    BB   L
B   BB    L
BBBB      L
B   BB    L
B    BB   L
B     BB  L
B     BB  L
BBBBBB    LLLLLLLL

Variables

There are multiple Data Types for Variables - Strings, Character, Integers, Floats, and more.

Let’s make a String Variable named x.

>>> x = "Hello World!"

>>> x
'Hello World!'

Now let’s use the print() statement from earlier.

>>> print(x)
Hello World!

You can reassign variables to be different types and values.

>>> x = 1

>>> x
1

>>>print(x)
1

You can also do simple mathematics when the variables are of the types float or integer.

>>> x + 1
2

>>> x + 1.0
2.0

If you wish to add a variable or a number to a print statement that also has a string in it use the .format() method.

x = 1
three = 3.0
print("Hello {}! {} + {} =".format("World", 2.0, x, three))

Go ahead and play around with variables(“”,1,1.0…) and the different computations (*,+,-,%…) you can do. You’ll notice that you get errors when you attempt to compute types that do not work together. Then proceed to the next challenge.

Challenge 2

First, create a new file, next, change the name at the top of the editor to challenge2, remove everything below the “—…” line and then save it as “challenge2” in your “PyScript Projects” folder.

For this challenge you will need to utilize the secret weapon of every programmer… Stack Overflow and the internet.

Utilizing the .format() method and variables create a print() statement that adds x and y to get z. I have provided the shell of the code you will need below. Fill in the question marks with the appropriate variables, or values.

The output should be:

This print statement adds x and y to get z: 1 + 2.012345 = 3.01

So you will need to search online how to change the number of integers after the decimal point for floats when using a .format() method.

TIP:
you can comment out your previous code by placing a # before each line of your previous code. When you comment out code it will not be ran.

x = 1
y = 2.012345
z = ? # the sum of x and y

print("This print statement adds x and y to get z:" \
    + "{} + {} = {?}".format(? , ? , ?))