Decision Making - PowerPoint PPT Presentation

About This Presentation
Title:

Decision Making

Description:

Decision Making Decision Making Alter the flow of the program Conditionally controlling execution of a set of commands if-statement: if a b: print a if-Statement ... – PowerPoint PPT presentation

Number of Views:155
Avg rating:3.0/5.0
Slides: 10
Provided by: EmilyG160
Category:

less

Transcript and Presenter's Notes

Title: Decision Making


1
Decision Making
2
Decision Making
  • Alter the flow of the program
  • Conditionally controlling execution of a set of
    commands
  • if-statement

if a gt b print a
3
if-Statement
if ltconditiongt ltdo somethinggt
One-way Decision
  • If the ltconditiongt is True, then execute
    statements in the body of the if-statement
  • If the ltconditiongt is False, then the body is
    skipped over

4
if-else-Statement
if ltconditiongt ltthisgt else ltthatgt
Two-way Decision Branching
  • If the ltconditiongt is True, then do commands
    specified in ltthisgt
  • If the ltconditiongt is False, then do commands
    specified in ltthatgt

5
if-elif-else-Statement
if ltconditiongt ltthisgt elif ltcondition2gt
ltthatgt elif ltcondition3gt ltsomething
elsegt else ltthatgt
Multi-way Decision
6
Local Time
  • Get local time and print out name of current month

from time import localtime get time yr, month,
day, hr, mins, secs, wkdy, doy, dlght
localtime() if month 1 print
'January' elif month 2 print
'February' elif month 3 print
'March' ... else print 'December'
7
Local Time
  • Get local time and print out current month

from time import localtime get time yr, month,
day, hr, mins, secs, wkdy, doy, dlght
localtime() months 'Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec' print monthsmonth 1
8
Daylight Savings
from time import localtime get time yr, month,
day, hr, mins, secs, wkdy, doy, dlght
localtime() if dlight print 'Daylight
Savings Time' else print 'Not Daylight Savings
Time'
9
Drawing a Histogram
File histogram.py Purpose to generate a
histogram Author Required Libraries
Function Purpose Create Window Function
Purpose Draw and Label Axes (including Ticks)
Function Purpose Draw a single bar
Function Purpose Draw all bars Function
Purpose Import raw data from a file
Function Purpose Get Number of Bins from User
Write a Comment
User Comments (0)
About PowerShow.com