CPSC120 Lab 8

More Lists

  1. Roll The Dice

    Create a program in a file called dice.py that simulates rolling a pair of six-sided dice several thousand times by repeatedly generating two random integers between 1 and 6. The program should print the fraction of times that each value, 2 through 12, was rolled. To test the program you should compute the probability of rolling each value. For example, there is only 1 way to roll a 2 and there are 62 = 36 different possible rolls, so the probability of rolling a two is 1 / 36 = 0. 28

  1. Fuel Economy

    Create a program in a file called mileage_statistics.py that prompts the user to enter a string that consists of a comma separated list of EPA vehicle information. The program should print the manufacturer, model, and fuel economy of the vehicle with highest fuel economy. Assume that there is only one vehicle with the highest fuel economy. The file epa_2013_data.txt is an example of what input to the program should look like.

    You should create simple files to test your program on first. Once it is working you can test it on the real EPA data. You can use the EPA text file as input to your program by using redirection as follows:

    python3 mileage_statistics.py < epa_2013_data.txt

  2. Pascal’s Triangle

    Create a program in a file called pascal_triangle.py that prompts the user to enter a positive integer and prints the entered number of rows of Pascal’s Triangle. The first six rows of Pascal’s triangle look like:

    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1
    1 5 10 10 5 1


Submit a zip file of your code on the course Inquire site that uses your last names as the file name.