vendredi 3 juillet 2020

changing variable value inside IF loop

I have a function which accepts value 1-5, and I want to declare a global variable called 'Des' and make it change according to the option selected because I want to use that value in another function. I tried this but it does not work.

def mainNJ():
    #S_menu()
    print( "\033[1m" " PLEASE SELECT THE TYPE OF DONATION.")
    global Des
    validate = False
    while not validate:
        option = input(" INPUT VALUE 1 TO 5 : " "\033[0m")

    # For Selection 1 Animal Protection And Welfare.
        if option == str(1):
            validate = True
            print()
            print("\033[1m" " Animal Protection And Welfare Has Been Selected." "\033[0m")
            #Amount()
            Des1 = " Animal Protection And Welfare Has Been Selected."
            Des = Des1

    # For Selection 2 Support For Natural Disaster.
        elif option == str(2):
            validate = True
            print()
            print("\033[1m" " Support For Natural Disaster Has Been Selected." "\033[0m")
            #Amount()
            Des2 = " Support For Natural Disaster Has Been Selected."
            Des = Des2
    # For Selection 3 Children Education And Activities.
        elif option == str(3):
            validate = True
            print()
            print("\033[1m" " Children Education And Activities Has Been Selected." "\033[0m")
            #Amount()
            Des3 = " Children Education And Activities Has Been Selected."
            Des = Des3
    # For Selection 4 Children Education And Activities.
        elif option == str(4):
            validate = True
            print()
            print("\033[1m" " Caregiving And Health Research Has Been Selected." "\033[0m")
            #Amount()
            Des4 = " Caregiving And Health Research Has Been Selected."
            Des = Des4
    # For Selection 5 Conservation Of Cultural Arts.
        elif option == str(5):
            validate = True
            print()
            print("\033[1m" " Conservation Of Cultural Arts Has Been Selected." "\033[0m")
            #Amount()
            Des5 = " Conservation Of Cultural Arts Has Been Selected."
            Des = Des5

        else:
            print()
            print(" Invalid Option. Please Try Again.")
            #S_menu()

Aucun commentaire:

Enregistrer un commentaire