Programming with Python
Prof. Groner
Assignment 3: Repetition
THE PROBLEMS
This assignment has 3 parts, the questions for parts B and C can be found in the online textbook at the end of
Chapter 4 in the section "Programming Problems".
Blackboard > Content > Textbook: Introduction to Python for Data & Analysis
Part A) Sum of Sequence
Using looping, write a program that calculates the total of the sequence of integers from 1 to 10 and displays the
result. Use either the while or for statement. For your program, define a variable, for example n, set to 10, so
that it is easy to change and rerun.
Part B) Purchases - problem 1
Part C) Investment Alternatives - problem 5
See appendix in this assignment, about keeping track of a largest value.
Notes (parts B and C):
1) Use the Python input() function in combination with either int() or float() to prompt the user for the
required inputs and convert these to numbers.
2) For all assignments in the course, you should test your programs for different user inputs, including invalid inputs
(e.g., 0, negative, strings). At this point in the course, it is ok if your program works for valid inputs but does not work
for invalid inputs.
SUBMISSION DIRECTIONS
Write and submit 3 programs corresponding to the above 3 parts. Name your programs like:
<Lastname><Firstname>Asn3<part>.py
for example:
[Link]
[Link]
[Link]
The first line of each of your programs should have a comment like:
# John Smith – Assignment 3A
APPENDIX –Tracking the Largest
In order to keep track of a largest (or smallest) value, you can set one or more variables before a loop, and use if
inside the loop. For example, to keep track of the largest number a user enters:
# determine largest value of a sequence of user-entered numbers
largest = float('-inf') # -inf is a special Python value for -infinity
value = -1
while value != 0:
value = input('Enter a number (or 0 to end): ')
if value != 0 and value > largest:
largest = value
print('largest value = ', largest)