Difference between revisions of "CSC111 Lab 4 Solutions 2014"
(Created page with "--~~~~ ---- <onlydft> =Solution Programs= <source lang="python"> # Solutions for Lab 4 # D. Thiebaut # =========================================================== # Exercise ...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
---- | ---- | ||
<onlydft> | <onlydft> | ||
+ | |||
=Solution Programs= | =Solution Programs= | ||
<source lang="python"> | <source lang="python"> | ||
Line 135: | Line 136: | ||
% ( period, plural, newBalance ) ) | % ( period, plural, newBalance ) ) | ||
+ | # =========================================================== | ||
+ | # Challenge 4-5 | ||
+ | print( "\n========================\nChallenge 4-5\n========================" ) | ||
+ | |||
+ | print( "please enter positive integers at the prompt. Enter -1 to stop" ) | ||
+ | sum = 0 | ||
+ | x = 0 | ||
+ | count = 0 | ||
+ | while x != -1 and sum < 20: | ||
+ | x = int( input( "Enter a positive integer (-1 to stop): " ) ) | ||
+ | if x != -1: | ||
+ | sum = sum + x | ||
+ | count = count + 1 | ||
+ | |||
+ | print( "The sum of the %d number(s) you have entered is %d" % ( count, sum ) ) | ||
</source> | </source> | ||
+ | |||
+ | <br /> | ||
</onlydft> | </onlydft> | ||
− | + | ||
<br /> | <br /> | ||
<br /> | <br /> |