程序代写 Control Flow: elif

Control Flow: elif
The University of credit: https://xkcd.com/518 Page 1

Lecture 2a: Summary

Copyright By PowCoder代写 加微信 powcoder

– Selection statements allows the flow of execution to follow a specific branch depending on the condition.
– Different types of branching:
if Nested ifs The University of Sydney

Control Flow: if…else
– Syntax: – Flowchart
if : Statement 1
elseS:tatement 2
DO NOT put expressions after keyword else.
The University of 3

Example – Odd or Even
– Write a program that prompts user for an integer and display if it is odd or even.
– EdLesson
The University of 4

Example – Fuel Warning
– What are the final values stored in fuelWarning and airConPower?
– Implementtheflowchartin Python. Ed Lesson
– Didweconsiderall possibilities of fuel?
The University of 5

Desk Check
– Trackeachvariablevalue and how it changes.
– Test by picking values that are normal, abnormal, on the boundary…
airConPower
fuelWarning
The University of 6

Control Flow: if… elif…
– elif abbreviation of else-if.
– When you have more than two possibilities and need more than two branches.
– No limit on the number of elif statements.
– If there is an else clause, it has to be at the end. Not
syntactically needed to have one.
– Conditionischeckedinorderofappearance.Ifthefirstis false, the next is checked and so on. Only the first true branch runs.
The University of 7

Example – Checking a, b, c
– Whatwillbetheoutputofthisprogram?
– Whathappensifcharissetto’z’? – Ed Lesson
The University of 8

Example – How much fine?
Determine the value of fine if speed is:
The University of 9

Lecture 2b: Summary
– Selection statements allows the flow of execution to follow a specific branch depending on the condition.
– Different types of branching:
if if-else if-elif
The University of 10

Reading This Week
– Chapter5.Downey,A.B.(2015).ThinkPython:HowtoThink Like a Computer Scientist (2e ed.). O’ , Incorporated.
– Chapter1.3.Sedgewick,R.,Wayne,K.,&Dondero,R.(2015). Introduction to programming in Python: An interdisciplinary approach. Addison- .
The University of 11

Example Behaviours
Example Scenario
Alice shares her study notes, notes she has written while revising the contents each week, to the ‘Study Group’ on WhatsApp.
Alice shares a Git link to the ‘Study Group’ on WhatsApp containing her source code files and flowcharts for the Project and weekly assessments.
Bob debates with Alice the correct answer for the Lecture quizzes.
Alice is stump for a week. She explains her problem to Bob and he suggests possible causes of the problem. Alice has new ideas on how to fix the problem as a result of the discussion.
Alice is stump for a week. She explains her problem to Bob and ask Bob to show her his solution. Bob opens his source code files and presents how he solves the question. Alice notes down the code block, re-writes them and submit them as her work.
The University of 12

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com