1 / 8

ITEC 109

ITEC 109. Lecture 10 More on Repetition / Choices. Review. Questions Mini-exam next Tuesday Iteration What is it How do we use it What are reasons why we would use it. Objectives. Extend choices beyond just one or the other Work on a homework assignment. Reality.

drago
Download Presentation

ITEC 109

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. ITEC 109 Lecture 10 More on Repetition / Choices

  2. Review • Questions • Mini-exam next Tuesday • Iteration • What is it • How do we use it • What are reasons why we would use it

  3. Objectives • Extend choices beyond just one or the other • Work on a homework assignment

  4. Reality • There are more than 2 cars in the world

  5. Example Extremely expensive Expensive Average Cheap

  6. Problem • Want to buy a car, but not multiple cars • Have $200k in the bank, want to get best car Are you always going to buy a camry? bankAccount=200000; if (bankAccount>500000): buyferrari(); bankAccount = bankAccount-500000; if (bankAccount > 60000): buybmw(); bankAccount = bankAccount -60000; if (bankAccount > 20000): camry.buy(); bankAccount = bankAccount – 20000;

  7. Multiple Choices • 1st choice • if • 2nd to Xth choice • else if • Last choice • else bankAccount=200000; if (bankAccount>500000): buyferrari (); bankAccount = bankAccount-500000; elif (bankAccount > 60000): buybmw(); bankAccount = bankAccount -60000; elif (bankAccount > 20000): buycamry(); bankAccount = bankAccount – 20000; Optional

  8. Homework • Create a program that asks the user to input one of four possible commands • Use if /elsif / else to call a function that implement the command • Come up with your own commands • Ideas • Turtle movement • Math formulas

More Related