CSCE 110: Programming I Spring 2019 Lab 4 General Instructions: Lab is due online by 11:59 pm of the due date. The assignment must be typed, not handwritten or scanned. Label your Python programs q<num>.py, where num is the question number. example, your solution to the first question is stored in the file q1.py. For Make sure you read the lab before you start. Your programs must match the output exactly as given for each question. This is important as one of the keys to being a good programmer is attention to details. If you forgot to bring a computer, you can check out a temporary laptop from ZACH 8 for a few hours (depending on the availability). Grading is based on correctness and clarity. Copying work from another source and submitting it as your own is plagiarism. The minimum penalty for plagiarism is a grade of zero. 1
Lab Questions 1. Computing leap years. Write a Python program stored in a file q1.py that asks for a starting year and an ending year and then prints all of the leap years between them (and including them, if they are also leap years). Leap years are divisible by 4. However, years divisible by 100 are not leap years unless they are also divisible by 400. Example #1. The user enters 2000 and 2015 as the starting and ending years (lines 1 2). The program then outputs the leap years in this range (lines 4 8). 1 Starting year : 2000 2 Ending year : 2015 4 Leap years between 2000 and 2015 5 2000 6 2004 7 2008 8 2012 Example #2. The user enters 1881 and 1907 as the starting and ending years (lines 1 2). The program then outputs the leap years in this range (lines 4 9). 1 Starting year : 1881 2 Ending year : 1907 4 Leap years between 1881 and 1907 5 1884 6 1888 7 1892 8 1896 9 1904 2
2. Palindromic numbers. A palindromic number is a number that is the same when written forwards or backwards. Write a Python program stored in a file q2.py that asks for a starting number and an ending number, and then prints all the palindromic numbers between them (and including them, if they are also palindromic numbers). Each palindromic number, must be separated by a space. Your program should also print the number of even and odd palindromic numbers generated. The ending number should not be greater than 1000. If the ending number is greater than 1000, print an error message and exit. Example 1 Starting number : 24 2 Ending number : 151 4 Palindromic numbers between 24 and 151 5 44 55 66 77 88 99 101 111 121 11 141 151 6 7 Number of even palindromic numbers : 8 Number of odd palindromic numbers : 10
. Matrix multiplication. Write a Python program stored in a file q.py that calculates the multiplication C of two matrices (A, B) of integers and calculates the transpose T of the resulting matrix C. The program should perform the following: - Ask for the number of rows, and the number of columns of matrix A on one line. - Ask for the number of rows, and the number of columns of matrix B on one line. - Ask for the numbers in each matrix. The number of rows or columns should not exceed 10. If the matrices A and B cannot be multiplied, the program should print an error message and exit. Example 1 Enter matrix A rows and columns : 4 2 2 Enter matrix B rows and columns : 2 Enter matrix A: 1 4 5 8 9 1 1 4 Enter matrix B: 0 9 1 2 1 5 6 Matrix A: 7 1 8 4 5 9 8 9 10 1 1 11 12 Matrix B: 1 0 9 14 1 2 1 15 16 Matrix C: 17 9 12 18 5 22 41 19 9 42 81 20 1 5 10 21 22 Transpose matrix T: 2 5 9 1 24 9 22 42 5 25 12 41 81 10 4
Submitting Your Assignment Once you have completed your programs, submit each of them (q1.py, q2.py, q.py) electronically. The extra credit question is optional. You may resubmit your files as many times as you need until the due date. Only the most recent submission is graded. You are required to include the following lines in the header of all your files: # File: filename.py # Author: Student name # Date: xx/xx/2019 # Section: Student section number # E-mail: student_email@tamu.edu # Description: # e.g. This program asks for... If you are in section 501 or 502, submit your files only on: mimir.io If you are in section 50, 504, 505 or 506, submit your files only on: gradescope.com 5