Download presentation
Presentation is loading. Please wait.
1
What are variables? Using input()
Computer Programming BSc in Digital Media, PSUIC 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
Run the Program in the Command Window
Find the program and then run it twice.
15
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
16
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
17
3. Farenheit to Celsius Converter
tempConverter.py means no newline str() changes a number to a string comments to help a reader
18
Execution the user typed this
19
Errors in a Program
20
Where's "line 10"? string() should be str()
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.