This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-02 14:41:51

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Can someone help me fix part of the code in a Python program?

I need help. The code is below:

Code:

import random, easygui

countryname = easygui.enterbox("Name your country!")
money = '5000'
population = '1000'
happiness = 4
land = '3000'
tax = '4'
easygui.msgbox("You have $" + money + ".")
easygui.msgbox("You have " + population + " people living in your country")
happiness = str(happiness)
easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
happiness = int(happiness)
easygui.msgbox("Your land size is " + land + " stalebears.")
easygui.msgbox("Your country's name is " + countryname)


while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    while happiness > 10:
        happiness = 10
    if random.randint(1, 100) == 1:
        answer = easygui.buttonbox("Would you like to set up a trade deal with a neighboring country to get more supplies?",
                          choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money + 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population + 15
            population = str(population)
            happiness = happiness + 2
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)        
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
            
        else:

            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 2:
            answer = easygui.buttonbox("The nearby country of East Walty is interesting in selling land to your country. One stalebear of land costs $10. Are you interested?",
                                       choices = ['Yes', 'No'])
            if answer == 'Yes':
                moreland = easygui.integerbox("How many stalebears are you willing to buy? You can buy a maximum of 99 stalebears at one time at $10 per stalebear.")
                money = int(money)
                if money - (moreland * 10) < 0:
                    easygui.msgbox("You cannot afford this amount of land to add to your country!")
                else:
                    land = int(land)
                    land = land + moreland
                    land = '%i' % land
                    land = str(land)
                    happiness = int(happiness)
                    happiness = happiness + 1
                    happiness = '%i' % happiness
                    happiness = str(happiness)
                    money = int(money)
                    money = money - (moreland * 10)
                    money = '%i' % money
                    money = str(money)
                    population = int(population)
                    population = population + (moreland * 10)
                    population = '%i' % population
                    population = str(population)
                    easygui.msgbox("You have $" + money + ".")
                    easygui.msgbox("You have " + population + " people living in your country")
                    easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                    easygui.msgbox("Your country consists of " + land + " stalebears.")
                    happiness = int(happiness)
                    while happiness > 10:
                        happiness = 10
            else:
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                happiness = str(happiness)
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
    if random.randint(1, 100) == 3:
        population = int(population)
        men = population
        population = str(population)
        men = men / 9
        men = '%i' % men
        men = str(men)
        easygui.msgbox("You are in a war with a nearby country. A third of our men will fight in the war.")
        easygui.msgbox("Our men were crushed by the opponent's army. We lost the war, population, land, and hope.")
        land = int(land)
        land = land - 1000
        lan = '%i' % land
        land = str(land)        
        happiness = int(happiness)
        happiness = happiness - 3
        happiness = '%i' % happiness
        happiness = str(happiness)
        money = int(money)
        money = money - 3000
        money = '%i' % money
        money = str(money)
        population = int(population)
        men = int(men)
        population = population - men
        population = '%i' % population
        population = str(population)
        men = str(men)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
        while happiness > 10:
            happiness = 10
    if random.randint(1, 100) == 4:
        population = int(population)
        men = population
        men = men / 9
        men = '%i' % men
        men = str(men)
        easygui.msgbox("You are in a war with a nearby country. A third of our men will fight in the war.")
        easygui.msgbox("Our men won the war!")
        land = int(land)
        land = land + 1000
        land = '%i' % land
        land = str(land)
        happiness = int(happiness)
        happiness = happiness + 3
        happiness = '%i' % happiness
        happiness = str(happiness)
        money = int(money)
        money = money + 3000
        money = '%i' % money
        money = str(money)        
        population = int(population)
        men = int(men)
        population = population + (men / 2)
        population = '%i' % population
        population = str(population)
        men = str(men)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
        while happiness > 10:
            happiness = 10
    if random.randint(1, 100) == 5:
        answer = easygui.buttonbox("The board of transportation is looking to build a national rail system in our country. Will you provide the money to do so?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 6:
        answer = easygui.buttonbox("The board of transportation is looking to build an airport. Can you provide the money to do so?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 7:
        easygui.msgbox("Congratulations! Some members of your country have decided to build a city!")
        money = int(money)
        money = money + 5000
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population + 5000
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 2
        happiness = '%i' % happiness
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
        while happiness > 10:
            happiness = 10
    if random.randint(1, 100) == 8:
        answer = easygui.buttonbox("Oh no! A tornado has caused a natural disaster in a prt of your country! Are you willing to provide aid?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 1000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 100
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 1000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 3
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint == 9:
        answer = easygui.buttonbox("A nearby country wants to be annexed into yours! Will you agree?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money + 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population + 4000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land + 3000
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 10:
        answer = easygui.buttonbox("East Walta is asking to buy some land. One stalebear will cost $10. Will you agree?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            landsell = easygui.integerbox("How many stalebears are you willing to sell? You can sell a maximum of 99 stalebears, unless you do not have that amount of land.")
            land = int(land)
            if landsell > land:
                land = str(land)
                easygui.msgbox("You cannot sell this amount of land! You only have " + land + " stalebears.")
            else:
                land = land - landsell
                land = '%i' % land
                land = str(land)
                money = int(money)
                money = money + (landsell * 10)
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population - (landsell * 10)
                population = str(population)
                happiness = int(happiness)
                happiness = happiness - 1
                happiness = '%i' % happiness
                happiness = str(happiness)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
                while happiness > 10:
                    happiness = 10
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 11:
        taxrate = easygui.integerbox("Tax Time! Create the next tax rate! It must be between 1 and 10%")
        if taxrate < 1:
            easygui.msgbox("The tax rate is too low!")
        elif taxrate > 10:
            easygui.msgbox("The tax rate is too high!")
        else:
            money = int(money)
            population = int(population)
            taxrate = int(taxrate)
            v = taxrate * 1000
            money = money + (v / population) 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - (taxrate / 3)
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 12:
        answer = easygui.buttonbox("Oh no! Riots have broken out! Will you choose to stop them?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 1000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 10
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 4
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money - 1500
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 2
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 13:
        easygui.msgbox("Towns are popping up!")
        money = int(money)
        money = money + 1500
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population + 1000
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 1
        happiness = '%i' % happiness
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
        while happiness > 10:
            happiness = 10
    if random.randint(1, 100) == 14:
        answer = easygui.buttonbox("Agricultural problems are occuring in parts of the country! What will you do?",
                       choices = ['Import food', 'Fix the soil and bring in water', 'Nothing'])
        if answer == 'Export food':
            money = int(money)
            money = money - 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        elif answer == 'Fix the soil and bring in water':
            money = int(money)
            money = money - 1500
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 2
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 2000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 4
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 15:
        answer = easygui.buttonbox("The school systems need more money to compete with other nations! Will you provide some?",
                                   choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 2
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                happiness = 10
    if random.randint(1, 100) == 16:
        answer = easygui.buttonbox("A space program wants to be formed by Congress. Do you wish to form one?",
                          choices = ['Yes', 'No'])
        if answer == 'Yes':
            spaceprogram = 'Yes'
            answer = easygui.buttonbox("The space program wishes to go to the Moon! Will you provide the funds to do so?",
                                       choices = ['Yes', 'No'])
            if answer == 'Yes':
                easygui.msgbox("We have made it to the Moon!")
                money = int(money)
                money = money + 500
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population 
                population = str(population)
                happiness = int(happiness)
                happiness = happiness + 4
                happiness = '%i' % happiness
                happiness = str(happiness)
                land = int(land)
                land = land
                land = '%i' % land
                land = str(land)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
                while happiness > 10:
                    happiness = 10
            else:
                money = int(money)
                money = money 
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population 
                population = str(population)
                happiness = int(happiness)
                happiness = happiness - 2
                happiness = '%i' % happiness
                happiness = str(happiness)
                land = int(land)
                land = land
                land = '%i' % land
                land = str(land)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
                while happiness > 10:
                    happiness = 10
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 2
            happiness = '%i' % happiness
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
            while happiness > 10:
                    happiness = 10
    if random.randint(1, 100) == 17:
        easygui.msgbox("Congratulations! You are now in an alliance with a nearby country!")
        money = int(money)
        money = money + 2000
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population 
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 1
        happiness = '%i' % happiness
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
        while happiness > 10:
            happiness = 10

I'm trying to have the happiness go down to ten when it goes above the maximum level of ten. However, when I run the program it does not work. Help!

Last edited by undefeatedgames (2012-05-02 15:24:49)


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#2 2012-05-02 15:01:43

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

happiness = 10
not
happiness == 10


http://i45.tinypic.com/28rnqki.jpg

Offline

 

#3 2012-05-02 15:04:38

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

poopo wrote:

happiness = 10
not
happiness == 10

I did happiness = 10 first
That didn't work

Last edited by undefeatedgames (2012-05-02 15:04:49)


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#4 2012-05-02 16:01:24

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Perhaps you should try breaking your program down into more manageable size chunks?  When the routine gets to be that big, it gets hard to figure out what is going on.  Define a few top-level functions, make sure they are working okay, then add in more detail until you get the desired result.

Also, while it isn't really wrong, there is no need to use a while loop to perform a single statement one time.  Just use the if statement

Code:

if happiness > 10:
    happiness = 10

And, while I haven't done Python in quite a while...it seems like you are initially setting happiness up to be a character string variable (because you are initializing it to a string value in quotes) but later you are comparing it to integers and finally you are assigning it an integer value.  I know Python is pretty forgiving, but I'm not sure it's that flexible.  You might want to decide once and for all if happiness is string or integer (or floating point) and than use the data type coercion functions to use it as other types.  Personally, I would probably set it up as a floating point and then use str and int to force it to other types as needed.

Last edited by Paddle2See (2012-05-02 16:08:21)


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2012-05-02 16:21:40

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Paddle2See wrote:

Perhaps you should try breaking your program down into more manageable size chunks?  When the routine gets to be that big, it gets hard to figure out what is going on.  Define a few top-level functions, make sure they are working okay, then add in more detail until you get the desired result.

Also, while it isn't really wrong, there is no need to use a while loop to perform a single statement one time.  Just use the if statement

Code:

if happiness > 10:
    happiness = 10

And, while I haven't done Python in quite a while...it seems like you are initially setting happiness up to be a character string variable (because you are initializing it to a string value in quotes) but later you are comparing it to integers and finally you are assigning it an integer value.  I know Python is pretty forgiving, but I'm not sure it's that flexible.  You might want to decide once and for all if happiness is string or integer (or floating point) and than use the data type coercion functions to use it as other types.  Personally, I would probably set it up as a floating point and then use str and int to force it to other types as needed.

No, you can do that.  Python is loosely typed.

Offline

 

#6 2012-05-02 16:38:01

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Paddle2See wrote:

Perhaps you should try breaking your program down into more manageable size chunks?  When the routine gets to be that big, it gets hard to figure out what is going on.  Define a few top-level functions, make sure they are working okay, then add in more detail until you get the desired result.

Also, while it isn't really wrong, there is no need to use a while loop to perform a single statement one time.  Just use the if statement

Code:

if happiness > 10:
    happiness = 10

And, while I haven't done Python in quite a while...it seems like you are initially setting happiness up to be a character string variable (because you are initializing it to a string value in quotes) but later you are comparing it to integers and finally you are assigning it an integer value.  I know Python is pretty forgiving, but I'm not sure it's that flexible.  You might want to decide once and for all if happiness is string or integer (or floating point) and than use the data type coercion functions to use it as other types.  Personally, I would probably set it up as a floating point and then use str and int to force it to other types as needed.

still not working


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#7 2012-05-02 17:00:56

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Paddle knows Python?

Anyway, is there an error message?

Offline

 

#8 2012-05-02 17:53:28

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

samtwheels wrote:

Paddle knows Python?

Anyway, is there an error message?

None. I'm trying to make the happiness level go down to 10 when it is above ten. Instead:

The happiness level is 11 out of 10.

Now how do I fix that?


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#9 2012-05-02 17:57:37

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

That's a little too much code.  Can you also give us a view of just the part of code you think is giving you trouble?

Offline

 

#10 2012-05-02 18:14:13

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Code:

while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    while happiness > 10:
        happiness = 10

Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#11 2012-05-02 18:16:52

samtwheels
Scratcher
Registered: 2011-03-20
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

undefeatedgames wrote:

Code:

while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    while [color=red]happiness[/color] > 10:
        happiness = 10

try casting this to an int too.

Offline

 

#12 2012-05-02 18:59:30

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

samtwheels wrote:

undefeatedgames wrote:

Code:

while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    while [color=red]happiness[/color] > 10:
        happiness = 10

try casting this to an int too.

doesn't work.


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#13 2012-05-02 19:56:20

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

It seems to be because you're setting your happiness back to 10 after you display the happiness...meaning if the happiness=11, your code says that then sets the happiness to 10.

So basically, it's not a matter of if you're setting it to 10 (you are) it's a matter of when relative to the display you're setting it to 10.

Last edited by AtomicBawm3 (2012-05-02 19:58:26)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#14 2012-05-02 20:44:40

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

undefeatedgames wrote:

Code:

while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    while happiness > 10:
        happiness = 10

Hm, just guessing off of 5 secs, try doing

Code:

while int(happiness) > -1 and int(population) > -1 and int(money) > -1:
    if happiness > 10: # Here's the change
        happiness = 10

Offline

 

#15 2012-05-02 22:00:39

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

Alright. I did AtomicBawn3's suggestion, and this is what I got:

Code:

import random, easygui

countryname = easygui.enterbox("Name your country!")
money = '5000'
population = '1000'
happiness = '4'
land = '3000'
tax = '4'
easygui.msgbox("You have $" + money + ".")
easygui.msgbox("You have " + population + " people living in your country")
easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
happiness = float(happiness
easygui.msgbox("Your land size is " + land + " stalebears.")
easygui.msgbox("Your country's name is " + countryname)


while int(happiness) > -1 and int(population) > -1 and int(money) and int(land) > -1:
    if random.randint(1, 100) == 1:
        answer = easygui.buttonbox("Would you like to set up a trade deal with a neighboring country to get more supplies?",
                          choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money + 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population + 15
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 2
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)        
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)           
        else:

            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 2:
            answer = easygui.buttonbox("The nearby country of East Walty is interesting in selling land to your country. One stalebear of land costs $10. Are you interested?",
                                       choices = ['Yes', 'No'])
            if answer == 'Yes':
                moreland = easygui.integerbox("How many stalebears are you willing to buy? You can buy a maximum of 99 stalebears at one time at $10 per stalebear.")
                money = int(money)
                if money - (moreland * 10) < 0:
                    easygui.msgbox("You cannot afford this amount of land to add to your country!")
                else:
                    land = int(land)
                    land = land + moreland
                    land = '%i' % land
                    land = str(land)
                    happiness = int(happiness)
                    happiness = happiness + 1
                    happiness = '%i' % happiness
                    if happiness > 10:
                        happiness = 10
                    happiness = str(happiness)
                    money = int(money)
                    money = money - (moreland * 10)
                    money = '%i' % money
                    money = str(money)
                    population = int(population)
                    population = population + (moreland * 10)
                    population = '%i' % population
                    population = str(population)
                    easygui.msgbox("You have $" + money + ".")
                    easygui.msgbox("You have " + population + " people living in your country")
                    easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                    easygui.msgbox("Your country consists of " + land + " stalebears.")
                    happiness = int(happiness)
            else:
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                happiness = str(happiness)
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
    if random.randint(1, 100) == 3:
        population = int(population)
        men = population
        population = str(population)
        men = men / 9
        men = '%i' % men
        men = str(men)
        easygui.msgbox("You are in a war with a nearby country. A third of our men will fight in the war.")
        easygui.msgbox("Our men were crushed by the opponent's army. We lost the war, population, land, and hope.")
        land = int(land)
        land = land - 1000
        lan = '%i' % land
        land = str(land)        
        happiness = int(happiness)
        happiness = happiness - 3
        happiness = '%i' % happiness
        if happiness > 10:
            happiness = 10
        happiness = str(happiness)
        money = int(money)
        money = money - 3000
        money = '%i' % money
        money = str(money)
        population = int(population)
        men = int(men)
        population = population - men
        population = '%i' % population
        population = str(population)
        men = str(men)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
    if random.randint(1, 100) == 4:
        population = int(population)
        men = population
        men = men / 9
        men = '%i' % men
        men = str(men)
        easygui.msgbox("You are in a war with a nearby country. A third of our men will fight in the war.")
        easygui.msgbox("Our men won the war!")
        land = int(land)
        land = land + 1000
        land = '%i' % land
        land = str(land)
        happiness = int(happiness)
        happiness = happiness + 3
        happiness = '%i' % happiness
        if happiness > 10:
            happiness = 10
        happiness = str(happiness)
        money = int(money)
        money = money + 3000
        money = '%i' % money
        money = str(money)        
        population = int(population)
        men = int(men)
        population = population + (men / 2)
        population = '%i' % population
        population = str(population)
        men = str(men)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
    if random.randint(1, 100) == 5:
        answer = easygui.buttonbox("The board of transportation is looking to build a national rail system in our country. Will you provide the money to do so?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 6:
        answer = easygui.buttonbox("The board of transportation is looking to build an airport. Can you provide the money to do so?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money - 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 7:
        easygui.msgbox("Congratulations! Some members of your country have decided to build a city!")
        money = int(money)
        money = money + 5000
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population + 5000
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 2
        happiness = '%i' % happiness
        if happiness > 10:
            happiness = 10
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
    if random.randint(1, 100) == 8:
        answer = easygui.buttonbox("Oh no! A tornado has caused a natural disaster in a prt of your country! Are you willing to provide aid?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 1000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 100
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 1000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 3
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint == 9:
        answer = easygui.buttonbox("A nearby country wants to be annexed into yours! Will you agree?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money + 3000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population + 4000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land + 3000
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 10:
        answer = easygui.buttonbox("East Walta is asking to buy some land. One stalebear will cost $10. Will you agree?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            landsell = easygui.integerbox("How many stalebears are you willing to sell? You can sell a maximum of 99 stalebears, unless you do not have that amount of land.")
            land = int(land)
            if landsell > land:
                land = str(land)
                easygui.msgbox("You cannot sell this amount of land! You only have " + land + " stalebears.")
            else:
                land = land - landsell
                land = '%i' % land
                land = str(land)
                money = int(money)
                money = money + (landsell * 10)
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population - (landsell * 10)
                population = str(population)
                happiness = int(happiness)
                happiness = happiness - 1
                happiness = '%i' % happiness
                if happiness > 10:
                    happiness = 10
                happiness = str(happiness)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 11:
        taxrate = easygui.integerbox("Tax Time! Create the next tax rate! It must be between 1 and 10%")
        if taxrate < 1:
            easygui.msgbox("The tax rate is too low!")
        elif taxrate > 10:
            easygui.msgbox("The tax rate is too high!")
        else:
            money = int(money)
            population = int(population)
            taxrate = int(taxrate)
            v = taxrate * 1000
            money = money + (v / population) 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - (taxrate / 3)
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 12:
        answer = easygui.buttonbox("Oh no! Riots have broken out! Will you choose to stop them?",
                                       choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 1000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 10
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 4
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money - 1500
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 2
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 13:
        easygui.msgbox("Towns are popping up!")
        money = int(money)
        money = money + 1500
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population + 1000
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 1
        happiness = '%i' % happiness
        if happiness > 10:
                happiness = 10
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)
    if random.randint(1, 100) == 14:
        answer = easygui.buttonbox("Agricultural problems are occuring in parts of the country! What will you do?",
                       choices = ['Import food', 'Fix the soil and bring in water', 'Nothing'])
        if answer == 'Export food':
            money = int(money)
            money = money - 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 1
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        elif answer == 'Fix the soil and bring in water':
            money = int(money)
            money = money - 1500
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 2
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population - 2000
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 4
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 15:
        answer = easygui.buttonbox("The school systems need more money to compete with other nations! Will you provide some?",
                                   choices = ['Yes', 'No'])
        if answer == 'Yes':
            money = int(money)
            money = money - 2000
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness + 2
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness 
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 16:
        answer = easygui.buttonbox("A space program wants to be formed by Congress. Do you wish to form one?",
                          choices = ['Yes', 'No'])
        if answer == 'Yes':
            spaceprogram = 'Yes'
            answer = easygui.buttonbox("The space program wishes to go to the Moon! Will you provide the funds to do so?",
                                       choices = ['Yes', 'No'])
            if answer == 'Yes':
                easygui.msgbox("We have made it to the Moon!")
                money = int(money)
                money = money + 500
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population 
                population = str(population)
                happiness = int(happiness)
                happiness = happiness + 4
                happiness = '%i' % happiness
                if happiness > 10:
                    happiness = 10
                happiness = str(happiness)
                land = int(land)
                land = land
                land = '%i' % land
                land = str(land)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
            else:
                money = int(money)
                money = money 
                money = '%i' % money
                money = str(money)
                population = int(population)
                population = population 
                population = str(population)
                happiness = int(happiness)
                happiness = happiness - 2
                happiness = '%i' % happiness
                if happiness > 10:
                    happiness = 10
                happiness = str(happiness)
                land = int(land)
                land = land
                land = '%i' % land
                land = str(land)
                easygui.msgbox("You have $" + money + ".")
                easygui.msgbox("You have " + population + " people living in your country")
                easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
                easygui.msgbox("Your country consists of " + land + " stalebears.")
                happiness = int(happiness)
        else:
            money = int(money)
            money = money 
            money = '%i' % money
            money = str(money)
            population = int(population)
            population = population 
            population = str(population)
            happiness = int(happiness)
            happiness = happiness - 2
            happiness = '%i' % happiness
            if happiness > 10:
                happiness = 10
            happiness = str(happiness)
            land = int(land)
            land = land
            land = '%i' % land
            land = str(land)
            easygui.msgbox("You have $" + money + ".")
            easygui.msgbox("You have " + population + " people living in your country")
            easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
            easygui.msgbox("Your country consists of " + land + " stalebears.")
            happiness = int(happiness)
    if random.randint(1, 100) == 17:
        easygui.msgbox("Congratulations! You are now in an alliance with a nearby country!")
        money = int(money)
        money = money + 2000
        money = '%i' % money
        money = str(money)
        population = int(population)
        population = population 
        population = str(population)
        happiness = int(happiness)
        happiness = happiness + 1
        happiness = '%i' % happiness
        if happiness > 10:
            happiness = 10
        happiness = str(happiness)
        land = int(land)
        land = land
        land = '%i' % land
        land = str(land)
        easygui.msgbox("You have $" + money + ".")
        easygui.msgbox("You have " + population + " people living in your country")
        easygui.msgbox("Your people have a total happiness of " + happiness + " out of 10.")
        easygui.msgbox("Your country consists of " + land + " stalebears.")
        happiness = int(happiness)

However, I got the EOF in Multiline Statement error, and I don't know what to do.


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

#16 2012-05-02 23:12:26

undefeatedgames
Scratcher
Registered: 2011-05-22
Posts: 1000+

Re: Can someone help me fix part of the code in a Python program?

I got it! Thanks guys!


Please call me udg or bearsfan, not undefeated.
Scratch and Misc.! Click here for Misc.'s Successorhttps://lh3.googleusercontent.com/-jkhes3yzmQk/T7G_BnxT9xI/AAAAAAAABYI/xhoN1Jk2M08/s513/sigp1.gif

Offline

 

Board footer