But when I run this I get NameError name alphabeta is not defined error How to solve this

0 votes
tree = [[[5, 1, 2], [8, -8, -9]], [[9, 4, 5], [-3, 4, 3]]]

root = 0

pruned = 0

def children(branch, depth, aplha, beta):

    global tree

    global root

    global pruned

    i = 0

    for child in branch:

        if type(child) is list:

           (nalpha, nbeta) = children(child, depth + 1, alpha, beta)

           if depth % 2 == 1:

              beta = nalpha if nalpha < beta else beta

           else:

              alpha = nbeta if nbeta > alpha else aplha

           branch[i] = alpha if depth % 2 == 0 else beta

           i += 1

        else:

          if depth % 2 == 0 and alpha < child:

              alpha = child

          if depth % 2 == 1 and beta > child:

             beta = child

          if alpha >= beta:

             pruned += 1

             break

    if depth == root:

       tree = alpha if root == 0 else beta

    return (alpha, beta)

    def alphabeta(in_tree=tree, start=root, upper=-15, lower=15):

      global tree

      global pruned

      global root

      (alpha, beta) = children(tree, start, upper, lower)

    if __name__== "__main__":

      print ("(alpha, beta): ", alpha, beta)

      print ("Result: ", tree)

      print ("Times pruned: ", pruned)

    return (alpha, beta, tree, pruned)

if __name__== "__main__":

      alphabeta(None)
Sep 6, 2020 in Python by MUHAMMAD
• 160 points

retagged Sep 7, 2020 by Gitika 1,296 views

Hi, @Muhammad,

Could you please mention on which line you are facing the error?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

when I run this, I get NameError: name 'state' is not defined error. How to solve this?

Hi@MUHAMMAD, I tried to run the exact code ...READ MORE

answered Sep 8, 2020 in Python by MD
• 95,460 points
2,854 views
0 votes
1 answer

i write this python to read dataset into panda data frame but im getting NameError: name 'true' is not defined. Below is the code:

change  def parse(path):   g = gz ...READ MORE

answered Mar 15, 2020 in Python by Abhishek Shingadiya
3,699 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 69,220 points
13,769 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,463 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,118 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP