Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting Started in Python

Similar presentations


Presentation on theme: "Getting Started in Python"— Presentation transcript:

1 Getting Started in Python

2 Some Python Types: int – This is a whole number like 2 or -56
float – This is a number with a decimal point like 3.14 or -5.0 string – This is a sequence of characters inside of single or double quotes “This is a string.” ‘This is a string.’

3 Assignment Statements
variable name = value Can never switch the sides around! Do not say value = variable name Good examples: name = “Sarah” numberOfHours = 5 Don’t do this (code will crash): “Sarah” = name 5 = numberOfHours

4 Assignment Statements
Is something like this ok? count = 4 count = count + 1 Actually, yes! Python evaluates the code on the “right-hand side” of the = first! After the right-hand side is calculated, Python assigns that value to the variable name on the left-hand side of the =

5 Getting Input from the User
Python allows us to ask for input from the user: variableName = input(“String with a question”) What the user typed gets saved into variableName Be careful – even if the user is typing a number, we always get the value as a string

6 Getting Input from the User
Why do we care if the value is a string? Can’t do any math on a string! (Like adding 5 to my name doesn’t make any sense.) We need to convert it to a number to do math on it!

7 Getting Input from the User
Example (convert number into int): age = input(“Enter your age: ”) age = int(age) Example (convert number into float): money = input(“How much money do you have?”) money = float(money)

8 Displaying Results After we do some calculations (or something) in the program, we want to display stuff to the user Use the print() function! print(“String to be displayed to the user”)


Download ppt "Getting Started in Python"

Similar presentations


Ads by Google