Python Programming


Assignment Rules:
Open book and notes assignment

  1. This homework tests your knowledge of File Handling, use of String methods, and use of Sets.
  2. Adhere to the naming conventions discussed in class for variable names, program name and function names
  3. Use meaningful names for variables, functions etc
  4. If there are two words in the variable use first word lowercase and first letter of second word upper case i.e., firstName or underscore between 2 words i.e first_name
  5. Include appropriate comments in the code
  6. Output should be displayed similar to as mentioned against each problem
  7. Indent the lines of code appropriately

1. char_analysis.py (40 points)

Write a program that reads the file’s contents and determine the following:

  1. The number of Uppercase letters in the file
  2. The number of Lowercase letters in the file
  3. The number of digits in the file
  4. The number of whitespace characters in the file

HINTS:

Define main():

Declare Local variables

Open file text.txt for reading. Use ‘text.txt’ file available under the Modules section in Canvas.

Use for loop to step through each character in the file.

Determine if the character is uppercase, lowercase, a digit, or space, and keep a running total of each.

Close the file.

Display the totals of uppercase, lowercase, digits, spaces.

Sample Output:

Uppercase letters: 29
Lowercase letters: 1228
Digits: 30

Spaces: 260

2. unique.py (30 points)

Write a program that opens a specified text file (text2.txt) and displays a list of all unique words found in the file.

HINTS:

Define main():

Declare Local variables

Open file text2.txt for reading. Use ‘text2.txt’ file available under the Modules section in Canvas.

Use ‘set’ method to find the unique words in the file and store each of them as an element of the set. 

Close the file.

Display all the unique words from the set.

Sample output:

These are the unique words in the text:
management.
name
been
later,
canceled,
is
Eastern,
delay
Eight
1,820
at
it
1867
official
world
and
company,….

3. name.py (30)

Write a program that gets a string containing a person’s first, middle, and last names, and displays their first, middle, and last initials. For example, if the user enters Susan Smith Miller, the program should display S.S.M.

Define main():

Declare Local variables

Prompt user to enter the full name

Use ‘split’ method to split the full name

Use for loop to get first character of each name as an initial

Convert the first character to upper case if it is already not in upper case

Display output

Sample output:

Enter your full name: Susan Smith Miller
S.S.M.