CSE 1310 - Assignments - Programming Assignment 4

The assignments will be graded out of 100 points. Create a text document entitled answers.xxx (where you replace xxx with whatever extension is appropriate, depending on the file format you use). Acceptable file formats are plain text, Word document, OpenOffice document, and PDF. Put your name and UTA ID at the top. Your answers that are not part of a program will be added to this file. Each task below will instruct you where to put your answers.


Task 1 (10 pts.)

The following code is supposed to ask the user for a string S and print the length of S as well as the first and last characters. It contains multiple errors. In your answers.xxx file, explain exactly what the errors are. Do not simply repeat any Python error message or just give a correction. Note that an error may be a conceptual error, not an error that causes the program to crash. Then, write a corrected version of the program and save as task1.py.

S = input('Enter a string: ')
length = len(S)
first_character = S[1]
last_character = S[length]
print('Length:', length)
print('First:', first_character)
print('Last:', last_character)

Task 2 (10 pts.)

The following code is supposed to:

The code contains multiple errors. In your answers.xxx file, explain exactly what is wrong. Do not just give a corrected version, but explain each error. Then write a corrected version and save it as task2.py

s = 'This isn't a number'
l = list(s)
for char in l:
    print(l[char])

Task 3 (10 pts.)

Write a program that:

For example:

Save the code in file task3.py.


Task 4 (30 pts.)

Write a program that:

For example:

Save the code in file task4.py.


Task 5 (10 pts.)

Write a program with the following specifications: For example:

Save your code in file task5.py.


Task 6 (10 pts.)

Write a program with the following specifications:

For example:

Save your code in file task6.py.


Task 7 (10 pts.)

Write a program with the following specifications:

For example:

Save your code in file task7.py.


Task 8 (10 pts.)

Write a program with the following specifications:

For example:

Save your code in file task8.py.


Suggestions

Pay close attention to all specifications on this page, including file names and submission format. Even in cases where the program works correctly, points will be taken off for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions.

How to submit

The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment4.zip (no other forms of compression accepted, contact the instructor or TA if you do not know how to produce .zip files). The zipped directory should contain your answers.xxx document and all the Python code files (task5.py, task6.py, etc).

Submission checklist