Difference between revisions of "CSC111 Lab 4 Solutions 2014"
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 20:31, 19 February 2014 (EST) | --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 20:31, 19 February 2014 (EST) | ||
---- | ---- | ||
− | + | <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 /> | <br /> | ||
+ | </onlydft> | ||
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |