Python Forum
(Not urgent) IDLE issue with methods
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Not urgent) IDLE issue with methods
#6
I don't think there is an Idle issue here. You only need a global variable which value can be shared by the different functions. Don't use the same names for the functions and the variable. This can be done simply like this
karma = 0

def init_karma():
    global karma # <- use this line if the function contains:  karma = ... or karma += ... etc
    if italyStart() == True:
        karma = 10

init_karma()  # <- don't forget to call the function that initializes the variable

def theyShouldntBeHere():
    while True:
        print("Wait, you're not supposed to be here! This is back-stage!")
        print("I guess you can [stay], but I'd rather you [leave].")
        print("")
 
        i = input(">")
        if i == "stay":
            print("Okay, I guess you can stay. Let's see what you did while you were here...")
            print("You had ", karma, " karma. Man, that's pretty ")
            if karma < 10:
                print("good.")
            elif karma > 10:
                print("screwed up.")
This method works well as long as there are not too many global variables. In this case, you'll have to learn how classes work.
Reply


Messages In This Thread
(Not urgent) IDLE issue with methods - by vinfer12 - Mar-22-2018, 06:50 PM
RE: (Not urgent) IDLE issue with methods - by Gribouillis - Mar-22-2018, 09:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Python Homework (Urgent help needed!!) chickenseizuresalad 6 4,355 Oct-11-2021, 01:59 AM
Last Post: Underscore
Exclamation urgent , Python homework alm 2 2,337 May-09-2021, 11:19 AM
Last Post: Yoriz
  urgent I got a syntax errors alm 2 5,902 Feb-28-2021, 02:54 PM
Last Post: alm
Heart Urgent homework help needed Medou 4 2,767 Nov-24-2020, 09:28 AM
Last Post: buran
  [Urgent] build code GodMaster 2 1,828 Mar-23-2020, 12:25 AM
Last Post: jefsummers
  Bifid Genkey (Urgent) Laura123 2 2,069 Mar-09-2020, 08:09 PM
Last Post: micseydel
  Python Homework Help *Urgent GS31 2 2,617 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Need help! Please! Urgent! foxylen 1 2,323 Feb-27-2019, 05:50 PM
Last Post: buran
  Machine Learning Antivirus [Urgent] Echoo0o 4 4,924 Jul-28-2017, 01:57 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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