Skip to content

Day One Script

albeaver edited this page Nov 26, 2016 · 7 revisions

Welcome to Python Day One

##This is the script, and will be used as a guide for presenting. This is intended for the presenter, however, you can look at this if you would like. I recommend you look at the code snippets for reference. If you would like to look at this, it is perfectly fine.


Printing

Printing is incredibly important in Python. Printing allows you to print to the console. Here is the command for printing:

print('string')

On your python command line, type in

print("Hello World")

Now press the ENTER key on your keyboard. You should see a new line that says Hello World.


Allow for a couple of minutes to play around with printing


##Variables Talk about what a variable is

a = 1

type in

print(a)

and 4 should be printed to the console

###Types of variables

There are lots of kinds of variables in Python, but these are the main ones

  • String (a string of characters such as a word, phrase, or sentence)
  • Integer (a number with no decimal points
  • Float (a decimal number)
  • Boolean (True or False) When using Booleans, always have the first letters of True and False capitalized

Strings are noted by quotes: for example "hello" is a valid string, while hello is not.

###Defining Variables Defining variables is very easy in python. All you need to do is type [name] = [value], replacing [name] and [value] with the variable name and value.

Try using different variables in interpreter

a = 1
print(a)
b = 2
print(b)
myName = "Alex"
print(myName)

AT THIS POINT, YOU NEED TO GET PEOPLE OUT OF THE INTERPRETER. SPEND A COUPLE OF MINUTES ON LEARNING HOW TO CREATE A NEW FILE Remember: all files [especially on Windows] need to have .py at the end.


Create a 'contact card' like seen at https://github.com/albeaver/cdsv-python-1/blob/master/contactplaygroundfinal.py


##Input and Output Input is incredibly useful in any program. You don't want the same exact thing to happen every time. Users want to be able to interact with the app. We can add interactivity very easily in Python.

Go back to interpreter

yourName = input("Enter your name: ")

When you run the code, you should see Enter your name: Now,

print(yourName)

Clone this wiki locally