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 3930792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:17:26+00:00 2026-05-19T23:17:26+00:00

Hello I am trying to write a program in python that asks the user

  • 0

Hello I am trying to write a program in python that asks the user to input a set of numbers of 1’s and 0’s and I want the program to tell me if I have and even number of zeros or an odd number of zeros or no zero’s at all. Thanks for your help!!

forstate = "start"
curstate = "start"
trans = "none"
value = 0


print "Former state....:", forstate
print "Transition....:", trans
print "Current state....", curstate
    while curstate != "You hav and even number of zeros":
        trans = raw_input("Input a 1 or a 0: ")
        if trans == "0" and value <2:
            value = value + 1
            forstate = curstate
        elif trans == "1" and value < 2:
            value = value + 0
            forstate = curstate
        curstate = str(value) + "  zeros"
        if value >= 2:
            curstate = "You have and even number of zeros"
        print "former state ...:", forstate
        print "Transition .....:", trans
        print "Current state....", curstate
  • 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-05-19T23:17:27+00:00Added an answer on May 19, 2026 at 11:17 pm

    Looks like you’re trying to do a finite state machine?

    try:
        inp = raw_input
    except NameError:
        inp = input
    
    def getInt(msg):
        while True:
            try:
                return int(inp(msg))
            except ValueError:
                pass
    
    START, ODD, EVEN = range(3)
    state_next = [ODD, EVEN, ODD]
    state_str  = ['no zeros yet', 'an odd number of zeros', 'an even number of zeros']
    
    state = START
    while True:
        num = getInt('Enter a number (-1 to exit)')
    
        if num==-1:
            break
        elif num==0:
            state = state_next[state]
    
        print 'I have seen {0}.'.format(state_str[state])
    

    Edit:

    try:
        inp = raw_input
    except NameError:
        inp = input
    
    START, ODD, EVEN = range(3)
    state_next = [ODD, EVEN, ODD]
    state_str  = ['no zeros yet', 'an odd number of zeros', 'an even number of zeros']
    
    def reduce_fn(state, ch):
        return state_next[state] if ch=='0' else state
    
    state = reduce(reduce_fn, inp('Enter at own risk: '), START)
    print "I have seen " + state_str[state]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am embedding python in C/C++ program. What I am trying to do is
Hello everyone thanks for looking into my problem. What I am trying to do
Hello I am having a problem with Django trying to get it deployed on
The usual hello world program I think is a terrible first program if you
Hey all I am trying to fill a html form using a java program
I'am currently trying to create and application (In c#) that parse a XML file
I am trying to dive into some x86 assembly programming on my Mac, but
I'm trying to perform a simple Linq find first query on a typed DataTable,
I was looking to do something like what I believe change control systems do,

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.