python programming
only 1 and 2
HIT137 Assignment 1, 2020
How to submit this assignment
Your submission should be written in a single PY file.
Save the py file using your lastname_firstname.py for example: Azam_Sami.py
Put all the solutions in one single PY file and then you can use Case-Switch statement to allow the user to select which program should
run first. I will show you how to use Case-Switch statement in the coming class. It is easy to use and gives you the flexibility to put your all
solutions in one PY file.
Clearly label each question and any sub-sections.
Provide maximum possible comments so the code becomes easier to read.
If your submission is difficult to understand, you will lose marks.
IMPORTANT TO NOTE: DO NOT use functions / commands to solve problems which were not taught in the class.
Question 1 Marks 6
Assume s is a string.
Write a program that prints a substring of numbers, the longest substring of s in which the numbers occur in descending order and compute the
average of the numbers found. For example, if s = ’56aaww1984sktr235270aYmn145ss785fsq31D0′, then your program should print.
Keep in mind you need to accept the string from the user.
Sample Input / Output
String of numbers: ‘561984235270145785310’
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Longest substring in numeric descending order is: 014578
Average: 4.167
In the case of ties, print the first substring. For example, if s = ’14erq72lkm79′, then your program should print
String of numbers: 147279
Longest substring in numeric descending order is: 147
Average: 4
Question 2 Mark 6
Write a program that encrypts and decrypts the user input. Note Your input should be only lowercase characters with no spaces.
Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the users input
should be offset by the distance value given by the user
For Encryption:
Take the string and reverse the string.
Encrypt the reverse string with each character replaced with distance value (x) given by the user.
For Decryption:
Take the string and reverse the string.
Decrypt the reverse string with each character replaced with distance value (x) given by the user.
Sample:
String input – cdu
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Encryption process udc -> xgf (encrypted)
The program should ask the user for input to encrypt, and then display the resulting encrypted output. Next your program should ask the user
for input to decrypt, and then display the resulting decrypted output.
Enter phrase to Encrypt (lowercase, no spaces): cdu
Enter distance value: 3
Result: xgf
Enter phrase to Decrypt (lowercase, no spaces): xgf
Enter distance value: 3
Result: cdu
Question 3 Mark 12
There is a file attached with your assignment, named mailbox-short.txt.
Write a program to prompt for a file name, and then read through the file and look for lines of the form:
X-DSPAM-Confidence: 0.8475
When you encounter a line that starts with X-DSPAM-Confidence: pull apart the line to extract the floating-point number on the line. Count
these lines and then compute the total of the spam confidence values from these lines. When you reach the end of the file, print out the
average spam confidence.
Your sample output of the program should be:
Enter the file name: mailbox-short.txt
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Average spam confidence: 0.894128046745
The End!!!
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD