Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:52:57+00:00 2026-06-13T12:52:57+00:00

I am fairly new to python. I have been asked to create a calculator

  • 0

I am fairly new to python.

I have been asked to create a calculator using only string commands, conversions between int/string/float etc.(if needed), and using functions is a requirement. while and for loops can also be used.

The program needs to take an input of the form x/y or x/y/z, where x y z are any positive or negative number. Where “/” can be replaced by addition multiplication and subtraction as well. And where any number of white spaces can exist between operands and operators. This is an idea of what I have so far.

I would have a unique definition for +,-,/, and *. I would create a function for what the user inputs. I would use “.lstrip” and “.rstrip” to get rid of white spaces.

Now what I am having trouble with is creating the input function. I am very new to functions and this is basically what I have. I know it isn’t much to work with but I am really stuck on how to properly enter the function.

def multiplication(x,a,y,b,z):
    if (a== "*"):
        return x*y
    if (b== "*"):
        return y*z

def division(x,a,y,b,z):
    if (a== "/"):
        return x/y
    if (b== "/"):
        return y/z

def addition(x,a,y,b,z):
    if (a== "+"):
        return x+y
    if (b== "+"):
        return y+z

def subtraction(x,a,y,b,z):
    if (a== "-"):
        return x-y
    if (b== "-"):
        return y-z

def (x,y,z):
    x=0
    y=0
    z=0

    zxc=int(input()):# this is where I get stuck and I don't know how to implement x,y,z into the input.

All help is appreciated. If you are unsure of whether the code you provide is too intense for my needs, please ask before wasting your time for me, making code that I can’t possibly use. I promise to reply ASAP.

Basically I am trying to find a way to split the inputted string AND THEN start calculations with it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:52:58+00:00Added an answer on June 13, 2026 at 12:52 pm

    Here is a possible solution outline using regular expressions. Error checking left as exercise. If this isn’t homework and you’d like to see the fleshed-out solution, view it here

    import re
    
    # input is a list of tokens (token is a number or operator)
    tokens = raw_input()
    
    # remove whitespace
    tokens = re.sub('\s+', '', tokens)
    
    # split by addition/subtraction operators
    tokens = re.split('(-|\+)', tokens)
    
    # takes in a string of numbers, *s, and /s. returns the result
    def solve_term(tokens):
        tokens = re.split('(/|\*)', tokens)
        ret = float(tokens[0])
        for op, num in <FILL THIS IN>:
            # <apply the operation 'op' to the number 'num'>
        return ret
    
    # initialize final result to the first term's value
    result = solve_term(tokens[0])
    
    # calculate the final result by adding/subtracting terms
    for op, num in <FILL THIS IN>:
        result +=  solve_term(num) * (1 if op == '+' else -1)
    
    print result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to Python and have been using Wing IDE to play around
I am fairly new to Python, so I welcome alternative approaches. I have a
I very new to Python, and fairly new to regex. (I have no Perl
I am fairly new to programming and to python and wxpython. I have looked
I'm just learning about python. I'm fairly new. I have the following code that
I'm currently launching a programme using subprocess.Popen(cmd, shell=TRUE) I'm fairly new to Python, but
I'm fairly new to both Django and Python. This is my first time using
I'm fairly new to Python and programming in general. I have done a few
I am fairly new to Python and using Python 3.2. I am trying to
I am new to python and I have been trying to change my php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.