CPSC120 Lab 1

Linux and Python

Create a directory called lab1 in your labs directory. All of the code you create today should go in the lab1 directory.

Classmates

In Emacs create a python program in a file called classmates.py. The program should print something like the following:

    Name        Hometown    Intended Major      Age
    ====        ========    ==============      ===
    Sally       Roanoke     Computer Science    18
    Alexander   Washington  Math                19

    The average age is 18.5 years.

Except the lines with Sally and Alexander’s information should be replaced with your and your lab partner’s information. Also add two more lines with information about two classmates sitting near you. The program should not use spaces to align columns. Instead use the tab character, “\t”.

The program should also print the average age of the four people. The output should be nicely formatted in a sentence that is all one line. The program should compute the average age using the Python addition and multiplication operators. When you test your program, be sure to verify that the calculation is correct.

U.S. Population

In Emacs create a python program in a file called population.py. The program should print what the U.S. popluation is projected to be in 25 years if the current population growth rate remains constant. All of these calculation should be performed using Python’s arithmetic operations and printed nicely labeled and formatted.

According to the U.S. Census the current U.S. population is approximately 314,301,306 and it is changing in the following ways:

There is a birth every 7.3 seconds./ There is a death every 12.0 seconds./ There is a new immigrant every 27.8 seconds.

Voyager 1

Voyager 1 is a space probe that was launched by NASA in 1977. It is currently the farthest man-made object from Earth.

In Emacs create a python program in a file called voyager.py. The program should print how long it takes a signal from Voyager 1 to reach the Earth and how long it would take voyager 1 to reach Proxima Centauri at its current velocity. These calculation should be performed using Python’s arithmetic operations and printed nicely labeled and formatted.

Currently, Voyager 1 is approximately 18,206,397,571 km from Earth. The Voyager 1 communicates with radio waves, which travel at the speed of light, 299,792,458 m/s. The Voyager 1’s velocity is 61,400 km/h. The nearest star to the Earth is Proxima Centauri at 4.2 light years. Voyager 1’s power comes from heat released by the radioactive decay of plutonium. It is projected that Voyager 1 will run out of power in the year 2025.

Submission

Submit a zip file of your code on the course Inquire site that uses your last names as the file name. To create a zip file from the terminal use the following command from you lab1 directory:

    zip LastnameLastname.zip *

Note, LastnameLastname should be replaced with the actual last names of you and your partner. The zip file only needs to uploaded by one person. However, be sure to also copy or email the zip file to your partner. To extract the files in a zip file from the terminal use the following command:

    unzip LastnameLastname.zip