Computer science 111
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Computer Science 111 PowerPoint PPT Presentation


  • 43 Views
  • Uploaded on
  • Presentation posted in: General

Computer Science 111. Fundamentals of Programming I Developing and Testing Programs. Start with a User Request. Write a program that converts pounds to kilograms. Determine the Inputs and Outputs. The input will be the number of pounds, as an integer or floating-point number

Download Presentation

Computer Science 111

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Computer science 111

Computer Science 111

Fundamentals of Programming I

Developing and Testing Programs


Start with a user request

Start with a User Request

Write a program that converts pounds to kilograms.


Determine the inputs and outputs

Determine the Inputs and Outputs

  • The input will be the number of pounds, as an integer or floating-point number

  • The output will be

    • a prompt for the number of pounds

    • A label, and the number of kilograms as a floating-point number


Example session with the program

Example Session with the Program

Enter the number of pounds: 330

The number of kilograms is 150.0


Gather information about the problem

Gather Information About the Problem

There are 2.2 pounds in a kilogram


Design the algorithm in pseudocode

Design the Algorithm in Pseudocode

Prompt the user for the number of pounds

Input pounds

Set kilograms to pounds / 2.2

Output the number of kilograms


Code as the convert script

Code as the convert Script

"""

File: convert.py

This program converts pounds to kilograms.

Input: the number of pounds, as an integer or float.

Output: the number of kilograms, as a float, suitably

labeled.

"""

convert.py

Start with the prefatory docstring, not as an afterthought!!!


Code as the convert script1

Code as the convert Script

pounds = float(input('Enter the number of pounds: '))

kilograms = pounds / 2.2

print('The number of kilograms is', kilograms)

convert.py

The Python shell

Test the program in IDLE first!


Test with several inputs

Test with Several Inputs

pounds = float(input('Enter the number of pounds: '))

kilograms = pounds / 2.2

print('The number of kilograms is', kilograms)

convert.py

The Python shell


Then test in a terminal window

Then Test in a Terminal Window

pounds = float(input('Enter the number of pounds: '))

kilograms = pounds / 2.2

print('The number of kilograms is', kilograms)

convert.py

The terminal


For monday

For Monday

Start Chapter 3


  • Login