Page 55 -
P. 55

connect branches


          The Python code needs

           interconnecting paths


           The solution’s mapped out, and now we know that the program code will
           need to have paths that match this:




                                                     print
          First branch                             ("You win!")
                    guess==5?                                  print                               print
                                                             ("Too high")                        ("Game over!")
                                         guess > 5?


                                                               print
                                                              ("Too low")
                               Second branch

           But isn’t there a problem here? In the design there are many interconnecting
           paths, but so far, we have only written code that contains just one branch:


                       if guess == 5:
                           print("You win!")
                       else:
                           print("You lose!")

           In the new code, we will need to connect two branches together. We need the
           second branch to appear on the false path of the first.






                        guess==5?

                                                                     guess > 5?
                                                We need to connect
                                                these two paths
                                                together





           So how do you connect branches together in Python?


           20    Chapter 1
   50   51   52   53   54   55   56   57   58   59   60