Run update21, if you haven't already, to create the cs21/labs/02. Then cd into your cs21/labs/02 directory and create the python programs for lab 2 in this directory (handin21 looks for your lab 2 assignments in your cs21/labs/02 directory):
$ update21 $ cd cs21/labs/02 $ pwd /home/your_user_name/cs21/labs/02
Your programs are graded on both correctness and style. Please review
the comments regarding programming style on the main page.
Write a program, in a file named line.py, that asks the user to enter the value of two points in the Cartesian plane and then computes the slope of the line defined by those points and the distance between the points (formulas are on p.73, exercises 6 and 7).
Here is what two runs of your program might look like:
$ python line.py Given two points, (x1, y1) and (x2, y2), this program computes the distance between them and the slope of the line they define Enter the x coordinate of the first point: 1 Enter the y coordinate of the first point: 1 Enter the x coordinate of the second point: 4 Enter the y coordinate of the second point: 5 The distance between (1,1) and (4,5) is 5.00 The slope of the line they define is 1.33 $ python line.py Given two points, (x1, y1) and (x2, y2), this program computes the distance between them and the slope of the line they define Enter the x coordinate of the first point: 6 Enter the y coordinate of the first point: 12 Enter the x coordinate of the second point: 10 Enter the y coordinate of the second point: 30 The distance between (6,12) and (10,30) is 18.44 The slope of the line they define is 4.50Try using string formating to limit the number of places printed beyond the decimal point.
To use math library function, remember to add this to the top of your program:
from math import *
Zeno's Dichotomy Paradox is a paradox about continuous motion: before one can reach his/her destination he/she must first arrive at the half-way point, but before he/she can reach the half-way point, he/she must first arrive at the half-way point of the half-way point, and so on. Since this process continues forever, one can never reach his/her destination.
Zeno's paradox can be written mathematically as the sum of the following infinite series:
1 1 1 1 1 -- + -- + -- + -- + -- + ... 2 4 8 16 32Since today we know that infinite series can have finite sums, we may not find Zeno's paradox so paradoxical.
Write a program, in a file named zeno.py, that computes the sum of the first n terms in the above series, given a value for n that is entered by the user. For example, a couple runs of your program may look like this:
$ python zeno.py This program computes the sum of the first n terms of the series based on Zeno's Dichotomy paradox Enter a value a value for n: 3 the sum of the first 3 terms is 0.875 $ python zeno.py This program computes the sum of the first n terms of the series based on Zeno's Dichotomy paradox Enter a value a value for n: 20 the sum of the first 20 terms is 0.999999046326
$ python acronyms.py This program creates acronyms from a phrase. Enter a phrase: the World needs one more acronym The acronym of "the World needs one more acronym" is: TWNOMA $ python acronyms.py This program creates acronyms from a phrase. Enter a phrase: to be or not to be The acronym of "to be or not to be" is: TBONTB