Python programming
1 HIT137 Assignment 1, 2019
HIT137 Assignment 1, 2019
How to submit this assignment
Your submission should be written in a single Py file.
Save the Py file using your lastname_firstname.py
Azam_Sami.py
Clearly label each question and any sub-sections.
Provide maximum possible comments so the code becomes
easier to read.
IMPORTANT TO NOTE: DO NOT use functions / commands to
solve problems which were not taught in the class.
2 HIT137 Assignment 1, 2019
Question 1 Marks 7
Assume s is a string of numbers. Write a program that prints the
longest substring of s in which the numbers occur in ascending order
and compute the average of the numbers found. For example, if s =
'561984235272145785310', then your program should print
Longest substring in numeric ascending order is: 14578
Average: 5
In the case of ties, print the first substring. For example, if s =
'147279', then your program should print
Longest substring in numeric ascending order is: 147
Average: 4
Question 2 Mark 10
Write a python program that prompts the user for the names of two
text files and compare the contents of the two files to see if they
are the same. If they are, the scripts should simply output “Yes”.
If they are not, the program should output “No”, followed by the
first lines of each file that differ from each other. The input loop
should read and compare lines from each file. The loop should break
as soon as a pair of different lines is found.
Note: Input file will be given by me for testing. You should create
your own file and check your program running on that file. You don’t
need to attach the txt file.
First file name: Master.txt
Second file name: Slave.txt
3 HIT137 Assignment 1, 2019
Question 3 Mark 05
Develop a python program that will determine if a department store
customer has exceeded the credit limit on a charge account. For each
customer, the following facts are available:
Account number
Balance at the beginning of the month
Total of all items charged by this customer this month
Total of all credits applied to this customer’s account this month
Allowed credit limit
The program should input each of the facts, calculate the new
balance (=beginning balance + charges – credits), and determine if
the new balance exceeds the customer’s credit limit. For those
customers who credit limit is exceeded, the program should display
the customer’s account number, credit limit, new balance and the
message “Credit limit exceeded”. Here is a sample input/output
dialogue:
Enter account number (-1 to end): 100
Enter beginning balance: 5394.78
Enter total charges: 1000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
Account: 100
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter account number (-1 to end): 200
Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00
Enter account number (-1 to end): -1 # -1 is terminating condition
4 HIT137 Assignment 1, 2019
Question 4 Mark 8
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
user’s input should be offset by the distance value given by the
user
For Encryption Process:
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
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
5 HIT137 Assignment 1, 2019
Question 5 Mark 10
Write a program that will analyse the string input and print
“accept” or “reject” based on the pattern given
Accept if it fulfils the following conditions
String length 9
3 small alphabet (3 lowercase letter)
3 number (3 digit)
3 big alphabet (3 uppercase letters)
1st alphabet should be capital
Last alphabet should be a number
Two consecutive alphabets can’t be small
Reject if any of the condition is absent
!End!