Presentation is loading. Please wait.

Presentation is loading. Please wait.

What are variables? Using input()

Similar presentations


Presentation on theme: "What are variables? Using input()"— Presentation transcript:

1 What are variables? Using input()
Let's Learn Python and Pygame Aj. Andrew Davison, CoE, PSU Hat Yai Campus 2. Variables What are variables? Using input()

2 1. What is a Variable? A variable is a "named tag" for data used in your programs "Aj. Andrew" tag data Python treats the tag name teacher as being a different name than Teacher "Teacher" is a string, not the tag name Teacher

3 Variables Using Number Data

4 Why are they called "Variables"?
a variable can change (the tag is given new data 5 9 first

5 Many Tags for One Piece of Data
Teacher "Aj. Andrew" GreatTeacher

6 Moving a Tag to New Data changing one variable (tag)
does not affect the other variable Great Teacher "Einstein "Aj. Andrew" Teacher

7 Numbers and Strings + means different things for numbers and strings
strings can use "…" or '…'

8 The New Me the "new" score is the "old" score + 2

9 2. Have a Program get Input from the User
Write the program "SayHello.py" in any text ediror (e.g. Notepad, Notepad++)

10 Load the Program into IDLE

11 Run the program in IDLE

12 the program user types this name
the program uses input() to assign the user's data to yourName, and then prints it

13 Run the Program Many Times
the user types in a different name each time

14 input() reads in a string
The data for variable x is the string "1234" This data is NOT the number 1234 use int() to change the data from a string to a number

15 Getting a number as input
The data for variable x is an integer The data for variable x is a float (a decimal) If Python wants an integer input, it will be upset if the user enters a float

16 3. Farenheit to Celsius Converter
tempConverter.py means no newline str() changes a number to a string comments to help a reader

17 Execution the user typed this

18 Errors in a Program

19 Where's "line 10"? string() should be str()


Download ppt "What are variables? Using input()"

Similar presentations


Ads by Google