title: while loop condition needs to check if dictionary contains items and return to main menu if not
body: <p>I have the following code:
  <a href="https://repl.it/JRi4/2" rel="nofollow noreferrer">https://repl.it/JRi4/2</a>
  in which I am trying to implement a while loop in the searchplayer() sub. </p>
  
  <p>Basically, I need to check to see if the dictionary player_info is full, and only then continue with the search. If it is empty (no items in player_info) then it needs to print "Add player details" and return to the mainmenu()</p>
  
  <p><strong>The code in question is here:</strong></p>
  
  <pre><code>def searchplayer():  
     print("===============SEARCH by player: Calculate average goals==================")
     name = input("Player name : ")
     if name in player_info.keys():
       #print student_info
        print ("Average player goals : ", str(sum(player_info[name].values())/3.0))
     else:
        print("Please enter a valid player name:")
     print()
     mainmenu()
  
  main()
  </code></pre>
  
  <p>I have tried the following, that does not work:</p>
  
  <pre><code>def searchplayer():  
     print("===============SEARCH by player: Calculate average goals==================")
     name = input("Player name : ")
     while player_info:
       if name in player_info.keys():
       #print student_info
        print ("Average player goals : ", str(sum(player_info[name].values())/3.0))
     else:
        print("Please enter a valid player name:")
     print()
     print("Nothing in player_info")
     mainmenu()
  
  main()
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>player_info not defined
  </code></pre>
  
  <p>The error suggests player_info is not defined, but it has been declared as a global variable</p>