Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that prompts the user to enter a phrase. Then for each character in the phrase, print out character, its ASCII code, and

Write a program that prompts the user to enter a phrase. Then for each character in the phrase, print out character, its ASCII code, and the character second to the left of the corresponding character of the string in ASCII table.

A sample run of your program should look like:

Enter a phrase: Hello letter ASCII two_letter_before H 72 F e 101 c l 108 j l 108 j o 111 m 

And another sample run:

Enter a phrase: BDE letter ASCII two_letter_before B 66 @ D 68 B E 69 C

Hint: If c is a character, ord(c) returns its ASCII code. For example, if c is 'H', then ord(c) returns 72. See Lab 2.

To right aligned the print out, use print("%6c %5i %17c"%(character, ASCII_code_of_character, two_letter_before_current_character)). You need to find out expression to represent current character, ASCII_code_of_current_character, and two_character_before_current_character.

Explanation: Use 6c since column header "letter" has 6 letters, c means character, for example, letter 'H' in string "Hello". Use 5i since column header "ASCII" has 5 letters, i means int, which is the ASCII code of the current letter. Use 17c since column header "two_letter_before" has 17 letters, c means a letter, which is the character two characters ahead of the current letter.

Note that some characters in ASCII code are not printable. For example, character with ASCII code 27 means ESC key in keyboard, which is not printable. Similarly, ASCII code 30 is record separator, which is not printable. Space character, which has ASCII code 32, is not printable.

When you test your print, do not include space, exclamation symbol ! (ASCII code 33), or double quotes symbol " (ASCII code 34), since the characters two positions before them are non-printable, you cannot check results visually.

Warning: do not forget to print column names "letter ASCII two_letter_before".

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago