Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QuESTION 2 (7 MARKS) Write a program which prints two different formats of a date. The date which needs to be reformatted always has a

image text in transcribedimage text in transcribed

QuESTION 2 (7 MARKS) Write a program which prints two different formats of a date. The date which needs to be reformatted always has a format similar to "7:10:1969 where the day number and the month number can be one or two digits and the year number is always four digits. The program prints the date in the following two formats: QUESTION 3 (7 MARKS) Write a program which simulates four transactions on a Visa credit card account. Initially the account has a balance of-$113. Each transaction is either a negative amount (a credit card purchase) or a positive amount (a payment). The amount of each transaction (purchase or payment) is a random integer between 15 and 200 inclusive. Below are the three statements which initialise the variables. Copy and paste them into your program. e a format similar to 07/10/1969" where the day number and the month number are always two digit numbers and the year number is always a four digit number e a format similar to July 7, 1969, i.e., the month name, followed by the day number initial balance-113 transaction min 15 transaction max-201 #1 bigger than the maximum followed by", followed by the four digit year number In the output, the amount of each transaction is displayed inside parentheses following the balance (after the transaction has been applied). The final two lines of output show the final balance and the overall sum of the four transactions. Note that there are 35 symbols in the two lines enclosing the final two lines of output. I have put a copy of the following four lines of code in a file named YourUsernameAl2.py on the Assignments website: https://www.cs.auckland.ac.nz/courses/compsci101ssc/assignments/ Copy and paste the four lines of code from the file into your program. months first 6January rebruary March months_last 6 July month 8tring8 = month8 f1r8t 6 + months last 6 Hint: in order to create a transaction which is either a purchase or a payment you will find it useful to generate a random number which is either -1 or 1. The random transaction amount is then multiplied by this number april May une August September october ovember Deceber Below are two example outputs using the completed program. Your program must give a correct output in exactly the same format as the outputs in the two examples below the date "15:12:2006" = Note that the variable, month_atringa, is a string where each month name followed by spaces takes up exactly ten spaces, i.e., the month name "January starts at index 0 and ends at index 9, the month name "February starts at index 120 and ends at index 129. [After obtaining the month name for the string, you will find it useful to use the string method, atrip(), in order to remove blank spaces from end of the month name string.] Initial viaa balance (dollars): -113 1-294 (-181) 2119 (175) 3: 65 (184) 4: 254 (189) starts at index 10 and ends at index 19,.., the month name December" Pinal viaa balance (dollara) 254 Sum of transactions: 5367 Below are three example outputs from the completed program (using the initial dates shown in the text box attached to each output). Your program must give the correct output in the same format as the outputs in the three examples below. Note that the number of"-signs in the two lines surrounding the dates is always eight more than the length of the concatenation of the two formats (separated by two spaces) Initiai visa balance dollara) 113 11 -295 (-182) 2:-274 (21) 3-129 (145) 4-289 (-160) Final visa balance (dollars) -289 sum of trans acions : S-176 the date15:12:2006 the date7:5:1969 Decenber 15, 2006 (15/12/2006) May 7. 1969 (07/05/1969) Include this exercise in a module (file), named YourUsernameA103.py, e.g., afer023A103.py January 1, 2016 (01/01/2016)thedate "111:2016 Include this exercise in a module (file), named YourUsemameA102.py,e.g, afer023A102.py QUESTION 4 (7 MARKS) Write a program which encrypts (or decrypts) a message. The message is always 25 letters in length. The last two lines of code below ensure that the message is always exactly 25 letters in length. QUESTION 5 (7 MARKS) Write a program which creates a word chain. The word chain starts with a word (of any length) and allows the user to create a new word by making one change (which always affects two consecutive letters) in the current word. In this way the user creates four new words in the chain. The user is first prompted for the index of the first of the two letters they wish to change (the first letter in the word is at index 0), then prompted for the replacement two letters, and then the program prints the changed word. This process is repeated four times. The word is always displayed in uppercase letters. Copy and paste the following statement which initialises the variable, word, into your program original worda-.pagg rm rfomieugasanrn! Ensures that the message is exactly 25 letters in length message originalworda + " " * 25 me88age=nes 8 age [ 0: 25] - Copy and paste the above statements which initialise the variable, 88 age, into your program. The program uses the following encryption method. First the 25 letter message is broken up into five 5 letter words, i.e., a five by five square of letters. Then the message is recreated by going down the five by five square of letters from left to right. For example, the message "abodefghijkimnopqratuy is reshaped into the following five rows: word -"atork Below are two example outputs using the completed program (using two different starting words). Your program must give the output in the same format as the outputs in the two examples below. Note that the string of"" symbols is exactly the same length as the final combined chain of words. abcde ghij klmno pgrat uvwny The word: STORK Replacement index: 2 Replacement letters: in The word: TERM Replacement index: 2 Replacement letters: am 1. Word is now: STINK Replacement index: 0 Replacement letters: bl and then the message is reconstructed going down each column starting from the first column to the last column: "afkpubg1qvchmrwdinexejoty 1. Word is now: TEAM Replacement index: e Replacement letters: pr 2. Word is now: BLINK Replacement index: 2 Replacement letters: an Below are three example outputs using the completed program (using three different starting messages). Your program must give the output in the same format as the outputs in the three examples below 2. Word is now: PRAM Replacement index: Replacement letters: cl 3. Word is now: BLANK Replacement index: 3 Replacement letters: st Original: pagg rm rf Encrypted: progranning in groat fun! 3. Word is now: CLAM Replacement index: 1 Replacement letters: hu 4. Word is now: BLAST original above all alwaya be kindl Encrypted: a aakbal iolwbnvlaede y STORK->STINK->BLINK->BLANK--8 LAST-> 4. Word is now:CHUM original: big Encrypted: bgai iovtegaota rehles egoa have little ears TERM-TEAM->PRAM->CLAM->CHUM->

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

Students also viewed these Databases questions