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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:19:20+00:00 2026-06-02T08:19:20+00:00

I have run into a weird problem. This code returns None instead of True,

  • 0

I have run into a weird problem. This code returns None instead of True, even though it goes in to the correct branch and evaluates to True:

edges = { (1, 'a') : [2, 3],
          (2, 'a') : [2],
          (3, 'b') : [4, 3],
          (4, 'c') : [5] }
accepting = [2, 5] 
loc = []
def nfsmsim(string, current, edges, accepting): 

    if string != "":
        if ((current, string[0]) in edges.keys()):
            global loc 
            loc = edges[(current, string[0])]
            print "edge found:",loc

    if (string == ""):
        print "string is over",current,accepting
        print type(current), type(accepting)
        if current in accepting : 
            print "1"
            return True
        else: 
            print "2"
            return 2
    # fill in your code here 
    elif (current, string[0]) in edges.keys():
        global loc
        string = string[1:]
        nfsmsim(string, loc[0], edges, accepting)
    elif len(loc)>1:
        global loc
        nfsmsim(string, loc[1], edges, accepting)


# This problem includes some test cases to help you tell if you are on
# the right track. You may want to make your own additional tests as well.
print nfsmsim("abc", 1, edges, accepting)

The output of this is :

 string is over 5 [2, 5]
<type 'int'> <type 'list'>
1
None (<< instead of True)
  • 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-02T08:19:22+00:00Added an answer on June 2, 2026 at 8:19 am

    This is a recursive function. When you reach the terminal case (string == ""), you return 1 or 2. That gets returned to the calling function — the previous call of nfsmsim. But that call of of nfsmsim doesn’t return anything! You need to get the value from the terminal call of nfsmsim and pass it on by returning it again.

    In other words, you need a return statement in each of these two branches of your if statement:

    elif (current, string[0]) in edges.keys():
        global loc
        string = string[1:]
        nfsmsim(string, loc[0], edges, accepting)
    elif len(loc)>1:
        global loc
        nfsmsim(string, loc[1], edges, accepting)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into a rather weird little problem. In the following code I
I'm fairly new to using MSSQL and have run into a weird problem. Given
I have run into a bit of a tricky problem in some C++ code,
I have run into this problem before but never quite solved it. I have
I have run into this problem a lot in the past, but never really
I have run into a rather weird problem. I have created the following query
I have run into a common, yet difficult problem. I do not use Photoshop
I have run into a problem trying to modify a form I myself have
I have run into a bit of a problem here: I had a problem-specific
I ran into a very weird problem today. Long story short, my function returns

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.