""" Goal/purpose: This file is a template for Physics 298owl assignments. You will build your arctan(1) series (as well as subsequent in-class and homework assignments) from it. The code here actually calculates the sum of the square roots of the integers 0, 1, 2, 3, 4. Assignment: unit 1 in-class machine exercise 2 Author(s): Monica and George Collaborators: Monica, George, and Neal (CS professor) File: p298owl_template.py Date: January 18, 2017 Time spent on this problem: 0.5 hr Reference(s): Stack overflow web site (see http://stackoverflow.com/documentation/python/193/getting-started-with-python-language#t=201701181706539874984) Physics 298owl course notes Physics 298 owl, University of Illinois at Urbana-Champaign, 2017 """ ################################### # Import libraries ################################### import numpy as np ################################### # Define and initialize variables ################################### # Accumulator variable accumulator = 0 # Index and upper limit variables for the loop lower_limit = 0 upper_limit = 4 ############################################################################### # Loop to sum the square roots of a bunch of integers ############################################################################### for index in range(lower_limit, upper_limit + 1): # calculate increment, then add it to accumulator. increment = np.sqrt(index) accumulator = accumulator + increment # I could have just added np.sqrt(index) to accumulator, without defining # increment. ############################################################################### # End of loop. Print the results. ############################################################################### print("all done. Sum of square roots is ", accumulator) ################################################################################