Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in Python which accepts one string at a time from the user, and displays the binary version of the string. Table

Write a program in Python which accepts one string at a time from the user, and displays the binary version Some examples of strings a user may enter (14 total possibilities) M 100 A+1  Task:  2. An assignment Testing Guidelines: Test the program with 5 different inputs and submit result screenshots along with the Following is the definition of the four arithmetic operations.  Addition: The addition operation on the twoÂ

Write a program in Python which accepts one string at a time from the user, and displays the binary version of the string. Table 1 shows the strings in column 1 and their binary value in column 2. The program accepts the strings based on following two rules. 1. Any string from column 1 and column 2 of Table 1 is a valid input string. M D A AM Table 1: Valid input strings a user may enter Colum 1 Column 2 001 010 100 101 Some examples of strings a user may enter (14 total possibilities) M 100 A+1 Task: 2. An assignment statement made up of strings only from fist column of the table. All combinations are possible. Some examples of strings a user may enter: D + 1 A + 1 D-1 M=D A=AM D=D-1 D+1=D-1 011111 110111 001110 1) Check if the string starts with a number or a character? If it starts with a number, print a message that shows it is a number and ask the user if they want to continue translating next string or they want to exit. If user enters exit (in any case upper/lower/combination), the program must display a message "Exiting..." and exit. If the user enters "continue", then ask for the next input string and proceed. If the string user entered does not start with a number then follow step 2 given below. 2) If the string starts with a character, then replace the substrings in that by binary value you can find for each part in this table and then print the binary string as output. (ignore "=") Example outputs of some input strings (On the left of arrow -> are the input values): D=D-1 -> 010001110" (colors are only to show you where the parts are coming from) M -> 001 AM = D+1 -> 101011111 And so on... Implementation Guidelines: For this program, use can use conditional statements, string methods, lists, loops and functions. Testing Guidelines: Test the program with 5 different inputs and submit result screenshots along with the source code. When you test the program, your script should be visible and the command line should be visible. Marks Breakdown: 1. Loop which asks for input string and exists only when user enters "exit" and if the user enters "continue", the loop must ask for a string. 1.0 marks 2. Checking if the string starts with a number of a character. 0.5 marks 3. If the string is composed of numbers (user entered any value form column2), display a correct message: 0.5 marks 4. Correct translation of input to output if the string is composed of characters: 2.0 marks 5. Input validation: if user enters a string which is not listed in the table above, display a descriptive error message and ask the user if he wants to try a new string or wants to exit. 1.0 marks 6. Comments which show author name, date created, description and explain the logic wherever required. 1.0 marks 7. Testing: Run your program for 2 input strings which are numbers, 6 input strings which are characters and 2 incorrect strings which are not in Table 1. Take the screenshots of testing and add in the word document. 1.0 marks 8. A program that has syntax errors and cannot be compiled will be graded out of 5 instead of out of 10. (You are losing 50% marks for any syntax errors you are leaving in your program.) Problem 2. Marks: 10.0 Problem Statement: In this problem, you will implement a calculator which performs the four basic arithmetic operations of addition, subtraction, multiplication and division, with our own definition. Input: The program should accept two integers of the same length. Implement the necessary checks to validate the input. If the user does not enter a valid number, ask the user to enter the valid number or type q to quit the program. When the input is validated, you should ask the user which operation they want to perform. The accepted operations are [+, -, *, /]. If user enters an invalid input, display the usage message and ask for valid input or q to quit the program. Once the operation has been validated, call the proper function to perform the correct arithmetic operation. Suppose the user enters following two numbers each one having six digits: (please note that 'a-f' and 'p- u' are all digits). (In your program it should work with any number of digits in each number.) X = abcdef Y = pqrstu Following is the definition of the four arithmetic operations. Addition: The addition operation on the two numbers is as follows. X+Y = apbqcrdsetfu O O O O O O Subtraction: O ReverseX = fedcba ReverseY = utsrqp X - Y = ReverseX + ReverseY (Here,+ is the addition operation defined above.) Multiplication O O O O O Division O Programming Requirements to Consider O XY = abcdefpqrstu YX = pqrstuabcdef X*Y = XY + YX (Here,+ is the addition operation defined above) O XY = abcdefpqrstu YX = pqrstuabcdef X/Y = XY - YX (Here, - is the subtraction operation defined above) Use the modular approach, main function to call other functions. Each function should take two parameters and return the result. Main function should print the result. Reuse the functions wherever possible. Make sure there is no redundant code. Marks Breakdown: 1. Input validation of numbers and quitting the program when user enters q . 1.0 marks 2. Input validation of numbers and quitting the program when user enters q. 1.0 marks 3. Operations: 6.0 marks (1.5 for each function) 4. Display the output: 1.0 marks 5. Testing: Run your program for three different lengths of numbers, once for each of the 4 operations and take the screen shots (12 screen shots in total). 1.0 marks 6. A program that has syntax errors and cannot be compiled will be graded out of 5 instead of out of 10. (You are losing 50% marks for any syntax errors you are leaving in your program.) 7. Please note that marks are distributed for output and programming style. It is not enough to get the correct result. It is important to following the programming requirements given above.

Step by Step Solution

3.34 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

def isvalidnumbernumber Check if the input consists of digits only return numberisdigit def getv... 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

Applied Calculus

Authors: Deborah Hughes Hallett, Patti Frazer Lock, Andrew M. Gleason, Daniel E. Flath, Sheldon P. Gordon, David O. Lomen, David Lovelock, William G. McCallum, Brad G. Osgood, Andrew Pasquale

6th Edition

1119275563, 9781119275565

More Books

Students also viewed these Programming questions