Python 如何在首次添加值后重置功能

Python 如何在首次添加值后重置功能,python,python-3.8,Python,Python 3.8,所以,游戏是这样运作的。。。如果你曾经玩过阿特拉斯,这将很容易理解 from easygui import * import sys import random from contextlib import contextmanager import colorsys class States: def __init__(self, state): self.state = state s1 = States("Alabama") s2 = Sta

所以,游戏是这样运作的。。。如果你曾经玩过阿特拉斯,这将很容易理解

from easygui import *
import sys
import random
from contextlib import contextmanager
import colorsys

class States:
    def __init__(self, state):
        self.state = state

s1 = States("Alabama")
s2 = States("Alaska")
s3 = States("Arizona")
s4 = States("Arkansas")
s5 = States("California")
s6 = States("Colorado")
s7 = States("Connecticut")
s8 = States("Delaware")
s9 = States("Florida")
s10 = States("Georgia")
s11 = States("Hawaii")
s12 = States("Idaho")
s13 = States("Illinois")
s14 = States("Indiana")
s15 = States("Iowa")
s16 = States("Kansas")
s17 = States("Kentucky")
s18 = States("Louisiana")
s19 = States("Maine")
s20 = States("Maryland")
s21 = States("Massachusetts")
s22 = States("Michigan")
s23 = States("Minnesota")
s24 = States("Mississippi")
s25 = States("Missouri")
s26 = States("Montana")
s27 = States("Nebraska")
s28 = States("Nevada")
s29 = States("New Hampshire")
s30 = States("New Jersey")
s31 = States("New Mexico")
s32 = States("New York")
s33 = States("North Carolina")
s34 = States("North Dakota")
s35 = States("Ohio")
s36 = States("Oklahoma")
s37 = States("Oregon")
s38 = States("Pennsylvania")
s39 = States("Rhode Island")
s40 = States("South Carolina")
s41 = States("South Dakota")
s42 = States("Tennessee")
s43 = States("Texas")
s44 = States("Utah")
s45 = States("Vermont")
s46 = States("Virginia")
s47 = States("Washington")
s48 = States("West Virginia")
s49 = States("Wisconsin")
s50 = States("Wyoming")

print("Starting")
img = "/Users/Aayan/Downloads/Extra Random Projects/images.png"
start = buttonbox(image=img, title="Welcome", msg="Hi, Welcome to Atlas", choices=["Lets Go"])
name = enterbox(title="Enter Your Name", msg="Name:")
contin = buttonbox(msg="Hi " + name, choices=["Continue"])
main_men = buttonbox(msg="Which Mode Do You Want", choices=["USA-Beta", "International Mode-Not Available", "Exit"])
if main_men == "USA-Beta":
    botmult = buttonbox(msg="Which Mode Do You want to play", choices=["Bot-Not Available", "Multiplayer"])
    if botmult == "Multiplayer":
        print("Preparing 0bacse01219128")
        the = enterbox(msg="What is the 2nd Player Name", title="2nd Player Name")
        msgbox(msg="Hello " + the)
        print("Game Starting")
        list1 = ['a', 'c', 'd', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w']
        cc = str(random.choices(list1))
        firstletter = msgbox("The First Letter Is " + cc)
        cc = str(random.choices(list1))
        first1 = enterbox("Enter State")
        lol = first1.lower()
        xz = list(first1)
        so = list(cc)

        # Error Gate
        if xz[0] == first1[0]:
            print("\033[1;32;40m Bright Green  \n" + "TEST PASSED 0C1AE")
        else:
            print("\033[1;31;40m Bright Red   \n" + "TEST FAILED ER!ORR")
        if first1 == States:
            print("\033[1;32;40m Bright Green  \n" + "TEST PASSED 0D1AF")
        else:
            print("\033[1;31;40m Bright Red   \n" + "TEST FAILED ER!ORR")

        def stachek():
            if lol == ("alaska","alabama","arizona","arkansas"):
                msgbox("Correct")

                stachek()
            elif lol == ("california", "colorado", "connecticut" ):
                msgbox("Correct")

                stachek()
            elif lol == ("delaware"):
                msgbox("Correct")

                stachek()
            elif lol == ("florida"):
                msgbox("Correct")

                stachek()
            elif lol == ("georgia"):
                msgbox("Correct")

                stachek()
            elif lol == ("hawaii"):
                msgbox("Correct")

                stachek()
                
            elif lol == ("idaho","illinois","indiana","iowa"):
                msgbox("Correct")

                stachek()
            elif lol == ("kansas", "kentucky"):
                msgbox("Correct")

                stachek()
            elif lol == ("louisiana"):
                msgbox("Correct")

                stachek()
            elif lol == ("maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri",
                         "montana"):
                msgbox("Correct")

                stachek()
            elif lol == ("nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york",
                         "north carolina", "north dakota"):
                msgbox("Correct")

                stachek()
            elif lol == ("ohio", "oklahoma", "oregon"):
                msgbox("Correct")

                stachek()
            elif lol == ("pennsylvania"):
                msgbox("Correct")

                stachek()
            elif lol == ("rhode island"):
                msgbox("Correct")

                stachek()
            elif lol == ("south carolina", "south dakota"):
                msgbox("Correct")

                stachek()
            elif lol == ("tennessee", "texas"):
                msgbox("Correct")

                stachek()
            elif lol == ("utah"):
                msgbox("Correct")

                stachek()
            elif lol == ("vermont", "virginia"):
                msgbox("Correct")

                stachek()
            elif lol == ("washington", "west virginia", "wisconsin", "wyoming"):
                msgbox("Correct")

                stachek()

            else:
                msgbox(msg= "Incorrect, You Lose", title= "Incorrect")

                stachek()

        if first1 == States:

            stachek()
        else:
            stachek()

问题是,我需要再次运行
stachek
功能,但当我这样做时,它不会在我第一次启动代码时重置,这意味着如果我得到正确的结果并按Ok转到第二次尝试,它会显示正确,它的意思是说
进入状态:
,然后如果正确,那么就做
进入状态:
,只要你一切都正确,它会做什么?它跳过问题,一直说正确

我不确定你想做什么,但我肯定问题在于缩进,这意味着您的代码不属于

如果您在指定了谁和谁一起玩之后试图向用户询问太多问题,我相信这段代码可能会对您有所帮助。我实际上更改了部分代码,希望你不介意

from easygui import *
import sys
import random
from contextlib import contextmanager
import colorsys

class States:
    def __init__(self):
        self.States = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida","Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]
        for i in range(0,len(self.States)):
            self.States[i] = self.States[i].lower()
        print("Starting")
        img = "/Users/Aayan/Downloads/Extra Random Projects/images.png"
        start = buttonbox(image=img, title="Welcome", msg="Hi, Welcome to Atlas", choices=["Lets Go"])
        name = enterbox(title="Enter Your Name", msg="Name:")
        contin = buttonbox(msg="Hi " + name, choices=["Continue"])
        main_men = buttonbox(msg="Which Mode Do You Want", choices=["USA-Beta", "International Mode-Not Available", "Exit"])
        self.list1 = ['a', 'c', 'd', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w']

        if main_men == "USA-Beta":
            botmult = buttonbox(msg="Which Mode Do You want to play", choices=["Bot-Not Available", "Multiplayer"])
            if botmult == "Multiplayer":
                print("Preparing 0bacse01219128")
                the = enterbox(msg="What is the 2nd Player Name", title="2nd Player Name")
                msgbox(msg="Hello " + the)
                print("Game Starting")        
                self.start_the_game()

    def start_the_game(self):
        i = 0 # for counting incorrect answers
        c = 0 # for counting correct answers
        t = 0 # for counting total number of questions asked
        while True:
            cc = str(random.choices(self.list1))
            msgbox("The First Letter Is " + cc)
            first1 = enterbox("Enter State")
            print(first1)
            if first1:
                lol = first1.lower()
                #xz = list(first1)
                print(lol)
                #so = list(cc)
                if lol in self.States:
                    msgbox("Correct")
                    c += 1
                else:
                    msgbox("incorrect")
                    i += 1
                t += 1
            else:
                break
        if t != 0:
            msgbox("correct percentage = " + str(c/t*100) + "%\nincorrect precentage = " + str(i/t*100))
        else:
            msgbox("you never played. exit game")
States()