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

  • SEARCH
  • Home
  • 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 8767191
In Process

The Archive Base Latest Questions

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

Python: So I am working on a program (which is a class assignment) that

  • 0

Python:
So I am working on a program (which is a class assignment) that will take an expression such as 3/4/5 or 32432/23423/2354325 or 3425*343/254235 or 43252+34254-2435, etc(for all operators from +,-,/,*). and will solve the expression.

I CANT USE EVAL!!

I cant use higher level codes, I am limited to, at most, using string manipulators from the below website to split the string.

http://docs.python.org/2/library/stdtypes.html#typesseq

My method is to look at the expression the user enters and then use a find function to find the OPERATORS, and then use these operators and a slicing function (eg. s[0:x]). What I have is below and unfortunately it isnt working: *note that the print statements are in there for debugging purposes only.
EDIT: why is x not defined when I run the program and enter an expression?

z= (input("expression:")).strip()

def finding(z):
    if "/" in z:
        x=z.find("/")
        print("hi1")
    elif "*" in z:
        x=z.find("*")
        print("hi2")
    elif "+" in z:
        x=z.find("+")
        print("hi3")
    elif "-" in z:
        x=z.find("-")
        print("hi4")
    else:
        print("error, not math expression")
    return x

def Parsing(z,x):

    x= finding(z)
    qw=z.s[0:x]
    print (qw)
# take the x-value from function finding(z) and use it to split 

finding(z)
Parsing(z,x)
  • 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-13T16:44:53+00:00Added an answer on June 13, 2026 at 4:44 pm

    If you’re just having trouble splitting the input into its parts, here’s something to help you. I left it as readable as I could so that you could at least understand what it does. I’ll explain any part of it if you need me to:

    def parse(text):
        chunks = ['']
    
        for character in text:
            if character.isdigit():
                if chunks[-1].isdigit():   # If the last chunk is already a number
                    chunks[-1] += character  # Add onto that number
                else:
                    chunks.append(character) # Start a new number chunk
            elif character in '+-/*':
                chunks.append(character)  # This doesn't account for `1 ++ 2`.
    
        return chunks[1:]
    

    Example usage:

    >>> parse('123 + 123')
    ['123', '+', '123']
    >>> parse('123 + 123 / 123 + 123')
    ['123', '+', '123', '/', '123', '+', '123']
    

    I’ll leave the rest up to you. If you aren’t allowed to use .isdigit(), you’ll have to replace it with lower-level Python code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python program that I am currently working on which is working
I'm developing a simple program which makes a Python script executable, and I'm working
Greetings, Forum. I'm working on a program in Python that uses Twisted to manage
I've written a working program in Python that basically parses a batch of binary
I have a program that runs in Python, without the console present (which is
i am working on a program in Python and using Pygame. this is what
I am working through trying to learn to program in Python and am focused
I am a Python and Qt newbie... I am working on a GUI program
all! Now I'm working on a p2p file share program in LAN(I use python).
I am working in a Python program with Javascript and DB. I have been

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.