CMSC 201

# Homework 4--Due 3/3

This homework must be submitted by 8pm on the due date to get any credit.

In this homework, we will be doing a series of exercises designed to make you practice using for loops and lists. Each one of these should be in a separate python file. For this assignment, you may assume that all the input you get will be of the correct type.

Please do not use the math library for this assignment.

For this assignment, you'll need to follow the class coding standards, a set of rules designed to make your code clear and readable. The class coding standards are here

1. part1.py Take two numbers as input, a width and height. Create a square where there are WIDTH numbers on each line, and HEIGHT rows. Remember, print(someString, end="") prints without a line break. It should look like this:
```Input a width: 4
Input a height: 2

1 2 3 4
5 6 7 8

```
Another example:
```Input a width: 3
Input a height: 5

1 2 3
4 5 6
7 8 9
10 11 12
13 14 15

```
2. part2.py Read in a list of numbers entered by the user. The user will enter integers, and when they are done they will type "end". You should print out the length of the longest subsequence of repeated elements. That is, the largest number of times something is repeated. So for the list [1, 4, 4, 3], you should print out "2", because there are two fours in a row. For the list [1, 2, 3, 3, 4, 1, 1, 1] you should print out "3", because there are three 1s in a row. Please format your results as follows:
```Enter a number: 1
Enter a number: 1
Enter a number: 2
Enter a number: 5
Enter a number: 5
Enter a number: 5
Enter a number: end

Longest run was 3 long.

```
3. part3.py For this problem, you're going to read in two lists of integers. The user will enter the first list, type "end", enter the second list, and type "end". You should print out a list that is a pairwise sum of these two lists. If the first list entered is [a, b, c] and the second list is [d, e, f, g] the you should print out the list [a + d, e + b, c + f, g]. You are guaranteed the input will be of the correct type. For example:
```
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: end
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: end

[5, 7, 9, 7]

```
The output should be EXACTLY in this format. Another example:
```
Enter a number: 1
Enter a number: -3
Enter a number: 4
Enter a number: end
Enter a number: 0
Enter a number: 2
Enter a number: end

[1, -1, 4]

```
4. part4.py Start with a variable named myList. myList will have the numbers 1, 9, 16, and 24 in it, in that order. Add this line to the top of your code:
```myList = [1, 9, 16, 24]
```
Prompt the user for a single integer, and insert that number into myList in such a way that myList is still in order (use the insert() or append() function). You can assume the number will not be in the list already. For example:
```Enter a number: 6

[1, 6, 9, 16, 24]
```
Or:
```Enter a number: -2

[-2, 1, 9, 16, 24]

```
You may not use the python built in sort function for this.

# Submitting

When you've finished your homework, use the submit command to submit the file. You must be logged into your account and you must be in the same directory as the file you're trying to submit. At the Linux prompt, type

submit cs201 HW4 part1.py part2.py part3.py part4.py

After entering the submit command shown above, you should get a confirmation that submit worked correctly:

Submitting part1.py...OK

Submitting part2.py...OK

Submitting part3.py...OK

Submitting part4.py...OK

If not, check your spelling and that you have included each of the required parts and try again.

You can check your submission by entering:

submitls cs201 HW4

You should see the name of the file that you just submitted, in this case parts 1 through 4.

 Adapted from UMBC CSHC's webpage design