Presentation is loading. Please wait.

Presentation is loading. Please wait.

Input and Output Upsorn Praphamontripong CS 1110

Similar presentations


Presentation on theme: "Input and Output Upsorn Praphamontripong CS 1110"— Presentation transcript:

1 Input and Output Upsorn Praphamontripong CS 1110
Introduction to Programming Spring 2017

2 Program Development Cycle
review Program Development Cycle Design the program Write the code Correct syntax errors Test the program Correct logic errors Understand the task the program will perform Break down the task into a series of steps Algorithm Translate an algorithm into code Two Representation Pseudocode Flowchart CS 1110

3 Algorithm  Pseudocode
review Algorithm  Pseudocode Exercise: Get 2 numbers from the user and display the larger number Algorithm: Get the first number Get the second number Compare the 2 numbers Display the larger number Pseudocode: Input the first number Input the second number If the first number > the second number, display the first number Otherwise, display the second number (what if the first number is equal to the second number?) CS 1110

4 Algorithm  Flowchart Exercise:
review Algorithm  Flowchart Exercise: Get 2 numbers from the user and display the larger number Start Input the first number Algorithm: Get the first number Get the second number Compare the 2 numbers Return the larger number Input the second number the first number is greater than the second number Yes No Display the first number Display the second number End CS 1110

5 Input – Process – Output
Exercise: Get 2 numbers from the user and display the larger number Input Process Output Check if the first number is greater than the second number The first number The larger number The second number input() function print() function CS 1110

6 Reading Input from the Keyboard
input(prompt) input(“What is your name? ”) Display the string “What is your name? ” on the screen Wait for the user to enter something and press Enter The user’s input is returned as a string name = input(“What is your name? ”) The user’s input is returned as a string and assigned to the variable name CS 1110

7 Variables A name that represents a value stored in the computer’s memory Creating variables with assignment statements statement = "Python is awesome!!!!" Python is dynamic typed language statement = "Python is awesome!!!!” statement = 4 Assignment operator statement Python is awesome String literal Type: string Numeric literal Type: int Variable reassignment CS 1110

8 Variable Naming Rules No Python’s key words No spaces
First character must be one of the letters (a…z or A…Z) or an underscore character ( _ ) Case sensitive Descriptive Consider t (or x) vs temp vs temperature How about payrate vs pay_rate vs payRate CS 1110

9 Displaying Output on the Screen
print(zero or more parameters) print(“Hello World”) Display the string “Hello World” on the screen print(“Hello ” + ”World”) print(“Hello”, ”World”) print() Display an empty line How about print(print())? CS 1110

10 Strings and String Literals
String = a sequence of characters E.g., “Hello World” String literal = a value/string that appears in a program, the actual value of the thing it represents E.g., print(“Hello World”) Must be surrounded by quotation marks Quotation marks used print("Python is awesome!") print('Python is awesome!') print('"Python is awesome!"') print('Python\'s awesome!') CS 1110


Download ppt "Input and Output Upsorn Praphamontripong CS 1110"

Similar presentations


Ads by Google