1 / 8

More While Loop Examples

More While Loop Examples . CS303E: Elements of Computers and Programming. Quote of the Day. Tell me and I forget. Show me and I remember. Involve me and I understand. - Anonymous Chinese Proverb. Question : Nested If Statements. What is the expected output? if(1<10 and 6<7):

gamba
Télécharger la présentation

More While Loop Examples

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. More While Loop Examples CS303E: Elements of Computers and Programming

  2. Quote of the Day Tell me and I forget. Show me and I remember. Involve me and I understand. - Anonymous Chinese Proverb

  3. Question:Nested If Statements What is the expected output? if(1<10 and 6<7): if(8>=10 or -1>0): print “if if” else print “if else” elif(4==4 and 9>=6): print “elif” A. if if B. if else C. elif D. None of the above

  4. Exercises • Write a program that calculates the product of the first n odd numbers (beginning at 0). • Write a program that reads n positive integers from the keyboard and then prints the maximum and minimum to the screen.

  5. Group Exercise • A perfect number is a number that is the sum of its divisors. The divisors of 6 are 1, 2, and 3 and they add up to 6 (1+2+3=6). Another perfect number is 28. The divisors of 28 are 1, 2, 4, 7, 14 and they add up to 28. There are not many perfect numbers. Write a program that takes as input an integer number and determines if it is perfect or not.

  6. Exercises • Prompt the user to enter exam scores, entering a negative number to quit. Find the average and print it.

  7. Exercises • Write a program that determines how long it takes an investment to double at a given interest rate. The input is the amount of the investment and an annualized interest rate. The output is the number of years it takes an investment to double.

  8. Question:While Loops When would you use a while loop? A. When you know exactly how many times the loop should execute B. When the loop will execute an indefinite number of times

More Related