1 / 11

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science. Chapter 2. The Software Development Process. Analyze the Problem Determine Specification Create a Design Implement Design Test/Debug the Program Maintain Program. Example Program: Temperature Converter. Problem:

Download Presentation

Python Programming: An Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python Programming:An Introduction toComputer Science Chapter 2 Python Programming, 2/e

  2. The Software Development Process • Analyze the Problem • Determine Specification • Create a Design • Implement Design • Test/Debug the Program • Maintain Program Python Programming, 2/e

  3. Example Program: Temperature Converter • Problem: • A US student in Europe needs to know what the temperature is in Fahrenheit. Python Programming, 2/e

  4. Example Program: Temperature Converter • Analysis – the temperature is given in Celsius, user wants it expressed in degrees Fahrenheit. • Specification • Input – temperature in Celsius • Output – temperature in Fahrenheit • Output = 9/5(input) + 32 Python Programming, 2/e

  5. 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 Python Programming, 2/e

  6. 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. Python Programming, 2/e

  7. 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! Python Programming, 2/e

  8. Example Program: Temperature Converter #convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def main(): celsius = eval(input("What is the Celsius temperature? ")) fahrenheit = (9/5) * celsius + 32 print("The temperature is ",fahrenheit," degrees Fahrenheit.") main() Python Programming, 2/e

  9. Example Program: Temperature Converter • Once we write a program, we should test it! >>> What is the Celsius temperature? 0 The temperature is 32.0 degrees Fahrenheit. >>> main() What is the Celsius temperature? 100 The temperature is 212.0 degrees Fahrenheit. >>> main() What is the Celsius temperature? -40 The temperature is -40.0 degrees Fahrenheit. >>> Python Programming, 2/e

  10. Example Program: Temperature Converter • Problem: • A US student in Europe needs to know the average distance between three cities in miles. • 1 Kilometer = 0.62 Mile Python Programming, 2/e

  11. The Software Development Process • Analyze the Problem • Determine Specification • Create a Design • Implement Design • Test/Debug the Program • Maintain Program Python Programming, 2/e

More Related