Getting Started With Python
Installation
There are a few ways to get started programming in Python. Depending on your environment you will need to work out the details of this before getting started. In most environments the easiest way to get started is to install Python and Idle. Installing Python
Idle is a simple way to get started coding and running Python files. At some point you may want to start using the command line or another mechanism, but Idle can be the easiest way to get started.
We always use the latest stable version of python (e.g. 3.5). Note that Python had a lot change from 2->3 so you need to be explicit which version of Python you are working with.
First Syntax: Input/Output
Here are the 3 things you need to know for your first project:
- Case and Whitespace matters: make sure to be consistent about case and whitespace.
- Variables are places to store values. Below I am setting my_number to
the value 5.
my_number = 5 - Input: asking a user to give you information is simple - you use the
input function. The only parameter to the function is a string that
will be presented to the user when requesting the information. The
function returns the value the user enters like so:
name = input('Please type your name: ') - Print: to print something to the screen you simply use the #print#
function:
print('Thank you') - There are multiple ways to format strings.
- Using the ‘+’ sign to concat strings:
'Hi ' + name - Using the ‘format’ function to format strings:
'Hi {}'.format(name)
- Using the ‘+’ sign to concat strings:
So your mission is to write a python program that asks a question (or maybe several! and prints out a friendly greeting.