[Tutor] don`t know how to begin...or what to do...

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Sep 18 18:37:03 EDT 2003


> i have to do the following..."Write a program that continually reads
in
> numbers from the user and adds them together until the sum reaches
100.
> Write another program that reads 100 numbers from the user and
prints out
> the sum."
>
> i don`t know what to do..

Divide and conquer, and use the Python >>> prompt to do it.

Write a program to read in two numbers and add them together.

Write a program that keeps on reading new numbers and
prints out the running total

Write a program that adds two numbers and prints a message
when the total is more than 100

Write a program that keeps on reading numbers and prints
out the running total if its greater than 100

Do the homework questions...

As to further clues you are correct. Use "while" to repeatedly
do something until some condition changes(like a total being
bigger than 100 say...). Use "for" to repeatedly do something
to or with each item in a sequence - the sequence could be a
list of numbers such as produced by the range() function for
example).

HTH,

Alan G.




More information about the Tutor mailing list