Exercises
Submission
To submit your solution, you will be creating a .zip file following the exercises below and upload it on Canvas under Assignment > Lab 1: Linux, Git, Python by September 5 at midnight (11:59 EST).
Late Submission
Please email us if you want to submit later than the deadline. Otherwise late penalty will be applied.
Exercises
Git (5 pts)
In this exercise you are required to set a git repository, for example inside your own Github namespace. You will be downloading the zip file of this repository and submit it to Canvas.
- Create a repository for your personal submissions
- Go to https://github.umich.edu/YOUR_USERNAME and click on “New Project” to create a new repository (replace
YOUR_USERNAMEwith your Github namespace) - Create a new Private repository and call it as your UMich username, e.g. if your Umich email is astark@umich.edu, call it astark
- Clone the repository to
~/ae740_personal(you will have a team submission later) runninggit clone https://github.com/YOUR_USERNAME/YOUR_UNIQUENAME.git ~/ae740_personal(replaceYOUR_UNIQUENAMEwith your uniquename) - Create a folder called
lab1
- Go to https://github.umich.edu/YOUR_USERNAME and click on “New Project” to create a new repository (replace
Shell (35 pts)
- Exercise 1 - Answer to the following questions
- Download
https://raw.githubusercontent.com/dlang/dmd/master/druntime/benchmark/extra-files/dante.txt(try usingwget) - Create a file called
exercise1.txtin~/ae740_personal/lab1and answer to the following questions- How many lines does it contains?
- How many words does it contains?
- How many lines are not blank?
- Push the file to git
- Download
- Exercise 2 - Output redirecting
- Install
fortune-modusingapt - After installation, type
fortunein your terminal to see a (hopefully) interesting proverb/quote - Run
fortune5 more times and each time redirect the output to a file calledfortunes.txtin~/ae740_personal/lab1(Hint: do not recreate the file 5 times - each time a new proverb should be added to the end offortunes.txt) - Push the file to git
- Install
Hint: For the first exercise you might want to use the command
wc(Word Count).
Python: RandomVector (40 pts)
In this exercise, you will implement a Python class called RandomVector. In the ae740_personal directory, create a Python virtual environment ae740_venv, that we will use throughout the course. Inside ~/ae740_personal/lab1, create a folder called RandomVector and clone the contents from https://github.com/UM-iRaL/ae740_labs/tree/main/lab1. This contains two files –
random_vector.py: Class definition.main.py: Main Python file, that imports theRandomVectorclass.
The class RandomVector will handle a list of random floating-point numbers. You are required to implement the following methods inside random_vector.py:
__init__(self, size, max_val=1.0)(constructor): Initialize a list of sizesizewith random values between 0 andmax_val(default value 1.0)mean(self): Returns the mean of the values in the random vectormax(self): Returns the maximum value in the random vectormin(self): Returns the minimum value in the random vectorprint(self): Prints all the values in the random vectorprint_histogram(self, bins): Computes the histogram of the values usingbinsnumber of bins betweenmin()andmax()and prints the histogram (see the example below)
When you’re done, create another file called main.py to test your implementation.
Note: We expect you to not use built-in functions like min(), max(), sum() or libraries like NumPy or Pandas for your implementation. Write the algorithms yourself.
If you complete the exercise correctly, when you run python main.py you should see output similar to:
$ python main.py
0.458724 0.779985 0.212415 0.066795 0.622538 0.999018 0.489585 0.460587 0.079561 0.185496 0.629162 0.328032 0.242169 0.139671 0.453804 0.083038 0.619352 0.454482 0.477426 0.090497
Mean: 0.393617
Min: 0.066795
Max: 0.999018
Histogram:
*** ***
*** ***
*** ***
*** ***
*** ***
*** ***
*** *** ***
*** *** *** *** ***