Python Forum
How to make global list inside function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make global list inside function
#1
from output import welcome, more, byebye, summary, invalid, emptylist, close
def food():
global choice
    x = 1
    while x > 0 and x <= 15:
        try:
            more()
            x = int(input("Enter your choice: "))
            choice.append(x)
        except:
            invalid()
    else:
        choice.remove(20)
        if len(choice) == 0:
            emptylist()
        else:
            choice.sort()
            print ("This is your selection:",choice)
            close()
print(choice)
the code is shown above but I can't do "print(choice)"
Larz60+ write Nov-25-2020, 09:14 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

I added for you this time. Please use bbcode tags on future posts.
Reply


Messages In This Thread
How to make global list inside function - by CHANKC - Nov-25-2020, 06:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't list require global keyword? johnywhy 9 834 Jan-15-2024, 11:47 PM
Last Post: sgrey
  with open context inside of a recursive function billykid999 1 584 May-23-2023, 02:37 AM
Last Post: deanhystad
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,354 May-22-2023, 10:39 PM
Last Post: ICanIBB
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 796 May-02-2023, 08:40 AM
Last Post: Gribouillis
  help me to make my password list in python >>> Oktay34riza 0 586 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
  Function global not readable by 'main' fmr300 1 1,352 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,125 Jan-09-2022, 02:39 AM
Last Post: Python84
  Make Groups with the List Elements quest 2 1,983 Jul-11-2021, 09:58 AM
Last Post: perfringo
Question How to make a 3D List of Excel Spreadsheets? chatguy 4 2,757 Jan-24-2021, 05:24 AM
Last Post: buran
  Finding global extrema of oscillating function JoeRogan 0 1,659 Dec-22-2020, 01:49 AM
Last Post: JoeRogan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020