QuestionQuestion

Problem #1
Let's build a calculator! The operators the calculator can handle are addition through "+", subtraction through "-", division through "/", multiplication through "x", exponentiation through "^", and modular arthimetic through "m"
Of course these are the symbols the user can type to invoke a mathematical operation, python may not be able to directly translate them. For example the "^" operator does not mean exponentiation in python!
For example running my my_calculator and entering 2^7 should return:
Your entry of 2^7 is equal to 128
For example: if my operation was 2++4 you should return
Your entry of 2++4 is not valid
You'll need conditional logic, some string parsing (lab 2/3), and to make rational design choices if the operation cannot be satisfied.
You may assume the user input string contains only two numbers seperated by an operation, you will not be tested against more than two numbers or multiple operations (or any characters)
I have imported the regular expression package for you to use, certainly not all solutions will leverage it but if you want to play around with regex a useful pythonic resource is:
Be aware the first number can be negative! -2+-4 should return -6!

(Do not use regex)

Problem #2
Some string operations
Rick and Morty have been captured by the galactic federation. They are not being held in adjacent cells but fortunately for our heros a corrupt guard is willing to pass them messages from each other (in exchange for money). In order to not have any culpability should things go wrong, he asks that their messages are encoded so he can have some plausible deniability as to what was happening.
You'll take a message (a string) lower case it, and shift it around (I would recommend lowercasing your string to only have to worry about one set of letters!!!). You'll leave spacing and punctuation intact. Your encryption function will take a string, and an offset. This offset will represent a shift in characters.
Take "cat" for example.
For example with an offset of positive 3, my string "cat" would shift to "fdw" (c->d,d->e,e->f) repeat for others
For example with an offset of negative 3, my string "cat" would shift to "zxq" (c->b,b->a,a->z) we are going backwards!
Of course decryption would simply revert these strings to their original forms.

(call the functions “encrypt” and “decrypt”)

Problem #3
Design a function to split a string into substrings of size n, adding a delimiter between each of the substrings.
split_and_delimit("magnify", 3, "7") = mag7nif7y
As evidenced by the example above, if you don't have an equal number of characters in your split strings you don't need a delimitter for the final one.
mag = 3 put a delimitter nif = 3 put a delimitter y = 1
no need for a delimitter after the final split string, even if the pieces are equal.

def split_with_d(string,num_splits,delim):

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

def calculator():
    # ask a user for an input
    entry = input("Entry:")
    operations = ["+", "^" "/", "*"]
   
    # check for invalid inputs
    for operation in operations:
       if entry.count(operation)>1 or entry.count("-")>2:
            print("Your entry of {entry} is not valid".format(entry=entry))
            return None
   
    # replace ^ with **
    if "^" in entry:
       entry_eval = entry.replace("^", "**")
    else:
       entry_eval = entry
   
    # print results
    try:...

By purchasing this solution you'll be able to access the following files:
Solution.py.

$43.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats