上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example Program:Temperature Converter ·Design -Input,Process,Output (IPO) -Prompt the user for input(Celsius temperature) Process it to convert it to Fahrenheit using F= 9/5(C)+32 Output the result by displaying it on the screen 11
Example Program: Temperature Converter • Design – Input, Process, Output (IPO) – Prompt the user for input (Celsius temperature) – Process it to convert it to Fahrenheit using F = 9/5(C) + 32 – Output the result by displaying it on the screen 11
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example Program:Temperature Converter Before we start coding,let's write a rough draft of the program in pseudocode o Pseudocode is precise English that describes what a program does,step by step. Using pseudocode,we can concentrate on the algorithm rather than the programming language. 12
Example Program: Temperature Converter • Before we start coding, let’s write a rough draft of the program in pseudocode • Pseudocode is precise English that describes what a program does, step by step. • Using pseudocode, we can concentrate on the algorithm rather than the programming language. 12
上游充通大学 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example Program:Temperature Converter 。Pseudocode: Input the temperature in degrees Celsius (call it celsius) Calculate fahrenheit as (9/5)*celsius+32 Output fahrenheit Now we need to convert this to Python! 13
Example Program: Temperature Converter • Pseudocode: – Input the temperature in degrees Celsius (call it celsius) – Calculate fahrenheit as (9/5)*celsius+32 – Output fahrenheit • Now we need to convert this to Python! 13
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example Program:Temperature Converter convert o.py A program to convert Celsius temps to Fahrenheit celsius input ("Enter a temperature:") fahrenheit 9.0 /5.0 celsius 32 print "The temperature is",fahrenheit,"degrees Fahrenheit." 14
Example Program: Temperature Converter # convert_o.py # A program to convert Celsius temps to Fahrenheit celsius = input(“Enter a temperature:") fahrenheit = 9.0 / 5.0 * celsius + 32 print "The temperature is", fahrenheit, "degrees Fahrenheit." 14
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Example Program:Temperature Converter #convert.py A program to convert Celsius temps to Fahrenheit by:Susan Computewell def main(): celsius input ("What is the Celsius temperature? ") fahrenheit (9.0/5.0)*celsius 32 print "The temperature is "fahrenheit,"degrees Fahrenheit." main ( 15
Example Program: Temperature Converter #convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def main(): celsius = input("What is the Celsius temperature? ") fahrenheit = (9.0/5.0) * celsius + 32 print "The temperature is ",fahrenheit," degrees Fahrenheit." main() 15