Starting from:

$34.99

CSCI2202 Lab 4-Lists, Strings & Floats Solution

Lists, Strings & Floats
1. Write a program that asks the user to input three numbers, and prints the largest and smallest values. e.g. For input: 6.7, 74, 9 the output is: The largest number input is 74 and the smallest 6.7
2. A leap year is a year (1582 and after) divisible by 4, unless it is a century year.
A century year is a leap year if it is divisible by 400.
Hence, 1900 is not a leap year, while 2000 is.
Write a program isLeapYear.py that takes a year as input and prints if the year input is or is not a leap year.
Once the rogram is working, compute the square roots of xList = [10,20,...90]. Compare the values to the values obtained using math.sqrt(). Henon’s Algorithm to find the square root y of a number x:
(a) Start with a guess: g
(b) Test: Is g ∗ g close (enough) to x? (c) If YES then DONE. Report: y = g
(d) Else update guess:
(e) g = gnew (f) goto 2.
4. The value of π is equal to the following infinite series:

(a) While we cannot compute the entire infinite series, we can get an approximation to the value by using the first n terms. Allow the user to input n. Name you program piSeries.py Experiment with n = 10, 100, 1000, 10000.
1
(b) As you can see, the value gets closer to the actual value of π as the number of terms increases. Make a copy of the program you made fro the exercise above and save it as piTolerance.py. Modify the program so that you keep adding terms such that the computation with n terms and the computation with n + 1 differs by less than 10e − 5 (1 part in 10000). Your program should print out the estimate of π and the number of terms used to obtain the value.
2

More products