lundi 25 mars 2019

If statements within def are not executing [on hold]

Hi I have been making a game in my free time, and it is mostly finished but I still have this one VERY annoying bug. Other than that, the game (I hope ) is complete.

For some reason, when I run this code, the if statements don't execute, have been looking for an answer but couldn't find any, was wondering if someone could help??

here is my code (sorry it is so long)

import time
import random
import sys

age = 0
hunger = 100
thirst = 100
money = 0
study = 6
stamina = 10
control = 0

def codetorepeat (age, hunger, thirst, money, study, stamina, control):

    refresh = 0
    while refresh < 50:
        print ('')
        refresh = refresh + 1

    print ('MAIN MENU')
    print ('')
    print ('STATS')
    print ('AGE : ', age)
    print ('HUNGER :', hunger, "/100")
    print ('THIRST :', thirst, "/100")
    print ('MONEY :', money, '$')
    print ('')
    print ('Options:')
    print ('Replenish hunger (rh)')
    print ('Replenish Thirst (rt)')
    print ('Invest in the stock Market (sm) ')
    print ('Work (w)')
    print ('Study (s)')
    print ('Go to the gym (gm)')
    print ('')

    if hunger == 0:
        print ('You have starved to death')
        print ('GAME OVER')
        sys.exit
    elif thirst == 0:
        print ('You have died because of de-hydration')
        print ('GAME OVER')
        sys.exit
    elif age == 100:
        print ('Your life has come to an end')
        print ('You lived a great life and have now died due to old age')
        sys.exit
    else:
        print ('What would you like to do?')
        action = input (':')
        age = age + 1
        hunger = hunger - 5
        thirst = thirst -5
        control = 1

        def checkinput (action):
            if action == ('rh') or action == ('rt') or action == ('sm') or action == ('w') or action == ('s') or action == ('gm'):
                return True
            else:
                return False

        while action == False:
            print ('Please enter  a valid option')
            print ('rh, rt, sm, w, s or gm')
           action = input (':')

        refresh = 0
        while refresh < 50:
            print ('')
            refresh = refresh + 1


        if action == ('rh') and control == 0:
            control = 1
            hunger = hunger + 20
            food = ['pizza', 'sandwich', 'pasta', 'salad', 'cerial', 'curry', 'sushi']
            food = random.choice (food)
            print ('You have eaten,', food)
            print ('your hunger is now', hunger)
            time.sleep (1)

        elif action == ('rt') and control == 0:
            control = 1
            thirst = thirst + 20
            drink = ['water', 'wine', 'beer', 'coca-cola', 'sprite', 'fanta', 'squash']
            drink = random.choice (drink)
            print ('You drank,', food)
            print ('your thirst is now', thirst)
            time.sleep (1)

        elif action == ('w') and control == 0:
            control = 1
            print ('You worked untill you were tired')
            print ('You currently earn ', study, 'per hour')
            print ('You currently can work for', stamina, 'hours')
            print ('To work longer hours, improve your stamina by going to the gym')
            print ('To earn more money per hour, study to get a better education')
            money = money + stamina * study
            time.sleep (1)

        elif action == ('s') and control == 0:
            control = 1
            study = study + 2
            stud = ['Read some books','Watched an informative video', 'Found better techniques']
            stud = random.choice (stud)
            print ('You have', stud)
            print ('You now earn', study)
            time.sleep (1)

        elif action == ('gm') and control == 0:
            control = 1
            stamina = stamina + 2
            gym = ['pumped some weights', 'did some push ups and sit ups', 'did some chin ups', 'went running']
            gym = random.choice (gym)
            print ('You', gym)
            print ('You can now work for up to ', stamina, 'hours at a time')
            time.sleep (1)

        elif action == ('sm') and control == 0:
            control = 1
            print ('How much money would you like to invest??')
            investmetamount = input (':')
            if investmentamount < money:
                print ('Which company would you like to invest in ??')
                print ('The chance of return is how likely you are to make your money back')
                apple = random.randit (1,100)
                print ('Apple (a) chance of return : ', apple)
                google = random.randit (1,100)
                print ('Google (g) chance of return : ', google)
                netflix = random.randit (1,100)
                print ('Netflix (n) chance of return : ', netflix)

                investment = input (':')
                def checkinput (investment):
                    if investment == ('a') or investment == ('g') or investment == ('n'):
                        return True
                    else:
                        return False

                while investment == False:
                    print ('Please enter a valid company')
                    investment = input (':')

                control = random.randit (1,100)
                if investment == ('a'):
                    if control < apple:
                        money = money + investmentamount
                        print ('Apples stock prices BOOM!!!, you now have : ', money, '$')
                    else:
                        money = money - investmentamount
                       print ('Apple stock prices plumet!!, you now have : ', money, '$')

                control = random.randit (1,100)
                if investment == ('g'):
                   if control < google:
                        money = money + investmentamount
                        print ('Google stock prices SKY ROCKET!!!, you now have : ', money, '$')
                    else:
                        money = money - investmentamount
                        print ('Google stock prices plumet!!, you now have : ', money, '$')

                control = random.randit (1,100)
                if investment == ('n'):
                    if control < netflix:
                        money = money + investmentamount
                        print ('Netflix stock prices SOAR!!!, you now have : ', money, '$')    
                    else:
                        money = money - investmentamount
                        print ('Netflix stock prices plumet!!, you now have : ', money, '$')

                time.sleep (1)

            else:
                print ('You dont have enough money to invest!')
                time.sleep (0.5)
                print ('...')
                time.sleep (0.5)
                print ('The markets have prevented you from making another investment')
                print ('Try again next turn')

    codetorepeat (age, hunger, thirst, money, study, stamina, control)

codetorepeat (age, hunger, thirst, money, study, stamina, control)

Aucun commentaire:

Enregistrer un commentaire