Q 1
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 = '561984235270135785310', then your program should print
Longest substring in numeric descending order is: 013578
Average: 4
Q 2
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:
- 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
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
Q 3
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
First file name: Master.txt
Second file name: Slave.txt
Q 4
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 Proccess:
- 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
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): apples
Enter distance value: 3
Result: xgf
Enter phrase to Decrypt (lowercase, no spaces): xgf
Enter distance value: 3
Result: