Error with math equation - python

My problem is that if you look at 'support' variable. (In the variable list) it doesn't apply to the Current Consumption. For EX. If I press 'S' and enter to start the game then press 'M' to display missions then press 'S' to choose the Survivors mission. And I recieve 2 survivors. That count won't add to the support for some reason and display "You are consuming 0.5 blah blah blah" not "You are consuming 0.7 blah blah blah" as it should be adding 0.1 per human? Sorry if this is hard to understand, I'm only 11 trying to program!
import random
from PIL import Image
print('\x1b[6;30;42m' + 'Zombie Survival Simulator' + '\x1b[0m')
print "Press [S] to start!"
resp = raw_input()
if 's' in resp or 'S' in resp:
foodmission = ['Convience Store','Grocery Store','Restraunt','Food Storage Area']
watermission = ['Convience Store', 'Old Gas Station', 'Water Tower','Toppled Coca-Cola truck.']
survivormission = ['Abandoned Refugee Camp','Bus','Army Camp','Train Station']
"FOOD"
#Pick Area
def pickfoodMission():
foodmis = random.choice(foodmission)
return foodmis
#Chance to get food
def chanceFood():
foodcha = random.randint(1,20)
return foodcha
#How much food you gain a mission
def foodPickup():
foodpick = random.randint(1,2)
return foodpick
"WATER"
#Pick the area
def pickwaterMission():
watermis = random.choice(watermission)
return watermis
#Chance for getting water
def chancewater():
watercha = random.randint(1,20)
return watercha
#Number of water you gain a mission
def waterPickup():
waterpick = random.randint(1,2)
return waterpick
"SURVIVORS"
#Pick the area
def picksurvivorMission():
survivormis = random.choice(survivormission)
return survivormis
#Chance for getting water
def chancehuman():
humancha = random.randint(1,20)
return humancha
#Number of water you gain a mission
def humanPickup():
humanpick = random.randint(1,2)
return humanpick
food = 3
water = 3
human = 5
healthy = 0
con = 0.1
level = 1
game = 1
new = 1
foodcon = 0
watercon = 0
support = 0.1 * human
newhuman = (human + (1 + (human / 5)) + healthy)
newwater = (water + (1 + (human / 5)) + healthy)
newfood = (water + (1 + (human / 5)) + healthy)
while game == 1:
if food <= 0 or water <= 0:
print('\x1b[7;30;41m' + 'You and your friends are dead.' + '\33[3m')
break
if food >= 3 or water >= 3:
healthy = healthy + 1
if food <= 2 or water <= 2:
healthy = healthy - 1
print "Current Resources: Food: " +str(food) + " Day(s) Water: " + str(water) + " Day(s)"
print "Current Survivors " + str(human)
if healthy <= -3 and healthy >= -1:
print "Current Survivors are " + ('\x1b[7;30;41m' + 'Nearly Dead' + '\33[3m')
if healthy == 0:
print "Current survivors " + ('\x1b[7;30;41m' + 'Are not healthy' + '\33[3m')
if healthy >= 1 and healthy <= 3:
print "Current Survivors are " + ('\x1b[7;32;43m' + 'Ok' + '\x1b[0m')
if healthy >= 3 and healthy <= 5:
print "Current Survivors are " + ('\x1b[7;32;43m' + 'Great' + '\x1b[0m')
if healthy >= 5 and healthy <= 7:
print "Current Survivors are " + ('\x1b[7;32;43m' + 'Excellent' + '\x1b[0m')
foodcon = support
watercon = support
food = food - support
water = water - support
print human
print support
print "You are consuming " + str(support) + " food and " + str(support) + " water per day"
if food - support <= 0 or water - support <= 0:
print('\x1b[7;30;41m' + 'You will not survive the next day.' + '\33[3m')
print "[M]issions [B]uilding [H]oard [E]nd Day"
resp = raw_input()
if 'M' in resp or 'm' in resp:
print "[F]ood [W]ater [S]urvivor"
resp = raw_input()
if 'F' in resp or 'f' in resp:
foodmis = pickfoodMission()
print "You go to a " + foodmis
foodcha = chanceFood()
if foodcha >= 14:
foodpick = foodPickup()
food = newfood
img = Image.open('food.png')
img.show()
print('\x1b[7;32;43m' + 'You are now at ' + str(newfood) + ' day(s) of food' + '\x1b[0m')
elif foodcha < 14:
print('\x1b[7;30;41m' + 'You come back empty handed.' + '\x1b[0m')
elif 'w' in resp or 'W' in resp:
watermis = pickwaterMission()
print "You go to a " + watermis
watercha = chancewater()
if watercha >= 14:
waterpick = waterPickup()
water = newwater
img = Image.open('water.png')
img.show()
print('\x1b[7;32;43m' + 'You are now at ' + str(newwater) + ' day(s) of water' + '\x1b[0m')
elif watercha <= 14:
print('\x1b[7;30;41m' + 'You come back empty handed.' + '\x1b[0m')
elif 's' in resp or 'S' in resp:
humanmis = picksurvivorMission()
print "You go to a " + humanmis
humancha = chancehuman()
if humancha >= 14:
humanpick = humanPickup()
human = newhuman
print('\x1b[7;32;43m' + 'You are now at ' + str(human) + ' survivor(s)' + '\x1b[0m')
img = Image.open('cats.jpg')
img.show()
elif humancha <= 14:
print('\x1b[7;30;41m' + 'You come back with no one else new.' + '\x1b[0m')
if 'B' in resp or 'b' in resp:
print "[F]ood"

You're never updating your support variable after you set it the first time so each time you print it out it's the same. Since support is dependent on human, you should either recalculate support every time human is updated or have a function like calculate_support() which calculates it when you need it.

As far as I can see at a quick glance you are only assigning value to the 'support' variable once in the code:
support = 0.1 * human
and I don't think this code gets to run again. Once support gets a value through this assignment statement it is not going to update even if you update the value of the 'human' variable.

Related

Python skips over the first if condition whenever adding these two specific lines of code

When looking at lines 54-59, there are two lines of code that state:
hero_health -= ENEMY_DAMAGE_AMOUNT
enemy_health -= HERO_DAMAGE_AMOUNT[damage_choice]
Whenever I add these lines of code to the if statement, the program just completely skips over this if statement and always outputs to the else statement. There aren't any syntax errors but whenever I remove these lines of code, the program runs both if conditions just fine. Also, when they are added, the code will skip to the else statement and for some reason only run one of the two print procedures. I'm not sure about what is causing this and would like a little feedback into what I might be doing wrong. Thank you!
import random
HERO_DAMAGE_AMOUNT = [15, 16, 17, 18, 19, 20]
ENEMY_DAMAGE_AMOUNT = 15
hero_health = 100
enemy_health = 100
enemy_choice = 0
hero_choice = 0
#------------------------------------------------------------------------------------------------------------------------------------
moon_background = Image("https://i.imgur.com/HWFNLRm.jpg")
moon_background.set_size(472.25, 480)
moon_background.set_position(0, 0)
add(moon_background)
hero_image = Image("https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/a8baa77f-c488-4769-bb75-a8a228144b41/debw2vq-26be5f8e-e91e-4009-b8f8-a56114f7efbe.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvYThiYWE3N2YtYzQ4OC00NzY5LWJiNzUtYThhMjI4MTQ0YjQxXC9kZWJ3MnZxLTI2YmU1ZjhlLWU5MWUtNDAwOS1iOGY4LWE1NjExNGY3ZWZiZS5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.2s7I8FsHnWciBzXtHubWMRVKaV4l4nyQumfc2v3PAs4")
hero_image.set_size(150, 150)
hero_image.set_position(get_width()/32, get_height()/3)
add(hero_image)
enemy_image = Image("https://i5.walmartimages.com/asr/ee3dd5b3-301e-4728-8457-d1e9905a6318_1.e358b4a32891c23b850a910b35d444fd.png")
enemy_image.set_size(200, 200)
enemy_image.set_position(get_width()/2, get_height()/3.65)
add(enemy_image)
block_image = Image("https://r7y4k4n7.stackpathcdn.com/3134-large_default/captain-america-shield-marvel-silver-coin-1-fiji-2019.jpg")
block_image.set_size(75, 75)
block_image.set_position(get_width()/12, get_height()/1.27)
add(block_image)
attack_image = Image("https://img.icons8.com/emoji/452/crossed-swards.png")
attack_image.set_size(75, 75)
attack_image.set_position(get_width()/1.3, get_height()/1.258)
add(attack_image)
#------------------------------------------------------------------------------------------------------------------------------------
def attack_and_block(x,y):
if x <= 307.6923076923077 + 75 and x >= 307.6923076923077 and y <= 381.55802861685214 + 75 and y >= 381.55802861685214:
enemy_choice = random.randint(1, 2)
hero_choice = 1
if hero_choice == enemy_choice:
damage_choice = random.randint(0,5)
hero_health -= ENEMY_DAMAGE_AMOUNT
enemy_health -= int(HERO_DAMAGE_AMOUNT[damage_choice])
print("You both attack. You do " + str(HERO_DAMAGE_AMOUNT[damage_choice]) + " damage. The enemy does " + str(ENEMY_DAMAGE_AMOUNT) + " damage.")
print("Your health is now: " + str(hero_health) + ". The enemy's health is now: " + str(enemy_health) + ".")
else:
print("You attacked but the enemy blocked it.")
print("Your health is still: " + str(hero_health) + ". The enemy's health is still: " + str(enemy_health) + ".")
elif x <= 33.333333333333335 + 75 and x >= 33.333333333333335 and y <= 369.2307692307692 + 75 and y >= 369.2307692307692:
enemy_choice = random.randint(1, 2)
hero_choice = 2
if hero_choice == enemy_choice:
print("You both blocked, nothing happened.")
print("Your health is still: " + str(hero_health) + ". The enemy's health is still: " + str(enemy_health) + ".")
else:
print("The enemy attacked, but you blocked it.")
print("Your health is still: " + str(hero_health) + ". The enemy's health is still: " + str(enemy_health) + ".")
add_mouse_click_handler(attack_and_block)

Python 2.7.8: printing color/value with out the format

I'm new to python and about a month into learning. I came across an issue where when I run this code it's supposed to print out the numbers in red. The second example shows what it really prints out and I'm stuck. Please help.
It's supposed to print ('Enemy HP:', 1150/1200)
but it actually prints ('Enemy HP:', '\x1b[91m1150/1200\x1b[0m\n')
import random
class bcolors:
HEADER = '\033[95m'
OKBLUE = "\x1b[94m"
OKGREEN = "\x1b[92m"
WARNING = '\033[93m'
FAIL = '\x1b[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class Person:
def __init__(self, hp, mp, atk, df, magic):
self.maxhp = hp
self.hp = hp
self.maxmp = mp
self.mp = mp
self.atkl = atk - 10
self.atkh = atk + 10
self.df = df
self.magic = magic
self.actions = ["Attack", "Magic"]
def generate_damage(self):
return random.randrange(self.atkl, self.atkh)
def generate_spell_damage(self, i):
mgl = self.magic[i]["dmg"] - 5
mgh = self.magic[i]["dmg"] + 5
return random.randrange(mgl, mgh)
def take_damage(self, dmg):
self.hp -= dmg
if self.hp < 0:
self.hp = 0
return self.hp
def get_hp(self):
return self.hp
def get_max_hp(self):
return self.maxhp
def get_mp(self):
return self.mp
def get_max_mp(self):
return self.maxmp
def reduce_mp(self, cost):
self.mp -= cost
def get_spell_name(self, i):
return self.magic[i]["name"]
def get_spell_mp_cost(self, i):
return self.magic[i]["cost"]
def choose_action(self):
i = 1
print(bcolors.OKBLUE + bcolors.BOLD + "Actions" + bcolors.ENDC)
for item in self.actions:
print(str(i) + ":", item)
i += 1
def choose_magic(self):
i = 1
print(bcolors.OKBLUE + bcolors.BOLD + "Magic" + bcolors.ENDC)
for spell in self.magic:
print(str(i) + ":", spell["name"], "(cost:", str(spell["cost"]) + ")")
i = 1
from classes.game import Person, bcolors
magic = [{"name": "Fire", "cost": 10, "dmg": 100},
{"name": "Thunder", "cost": 10, "dmg": 124},
{"name": "Blizzard", "cost": 10, "dmg": 100}]
player = Person(460, 65, 60, 34, magic)
enemy = Person(1200, 65, 45, 25, magic)
running = True
i = 0
print(bcolors.FAIL + bcolors.BOLD + "AN ENEMY ATTACKS!" + bcolors.ENDC)
while running:
print("======================")
player.choose_action()
choice = input("Choose action:")
index = int(choice) - 1
if index == 0:
dmg = player.generate_damage()
enemy.take_damage(dmg)
print("You attacked for", dmg, "points of damage.")
elif index == 1:
player.choose_magic()
magic_choice = int(input("Choose magic:")) - 1
magic_dmg = player.generate_spell_damage(magic_choice)
spell = player.get_spell_name(magic_choice)
cost = player.get_spell_mp_cost(magic_choice)
current_mp = player.get_mp()
if cost > current_mp:
print(bcolors.FAIL + "\nNot enough MP\n" + bcolors.ENDC)
continue
player.reduce_mp(cost)
enemy.take_damage(magic_dmg)
print(bcolors.OKBLUE + "\n" + spell + " deals", str(magic_dmg), "points of damage" + bcolors.ENDC)
enemy_choice = 1
enemy_dmg = enemy.generate_damage()
player.take_damage(enemy_dmg)
print("Enemy attacks for", enemy_dmg)
print("----------------------------")
print("Enemy HP:", bcolors.FAIL + str(enemy.get_hp()) + "/" + str(enemy.get_max_hp()) + bcolors.ENDC + "\n")
print("Your HP:", bcolors.OKGREEN + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bcolors.ENDC)
print("Your MP:", bcolors.OKBLUE + str(player.get_mp()) + "/" + str(player.get_max_mp()) + bcolors.ENDC + "\n")
if enemy.get_hp() == 0:
print(bcolors.OKGREEN + "You Win!", + bcolors.ENDC)
running = False
elif player.get_hp() == 0:
print(bcolors.FAIL + "Your enemy has defeated you!" + bcolors.ENDC)
running = False
Your code would work well in Python 3, where print is a function:
>>> print("x", "y")
x y
It means "print the first argument, then the separator (which defaults to a space), then the second argument.
In Python 2, though:
>>> print("x", "y")
('x', 'y')
prints a representation of the tuple containing your strings.
So, you can either use Python 3, which has many advantages, or change your code like this:
print("Enemy HP:" + bcolors.FAIL + str(enemy.get_hp()) + "/" +
str(enemy.get_max_hp()) + bcolors.ENDC + "\n")
# note the + instead of ,
in order to print a single string.
does it work for your others print ?
You have a double quote "" instead off simple '' on OKGREEN in class bcolors maybe it comes from here

Python 2.7.3 Code Loops Without a While Loop

I am relatively new to programming, so don't be surprised if there are some minor hiccups in the code, but the problem that is happening is that this code seems to loop itself, the whole thing and I don't understand why. I looked at the actual code that runs this function but it seemed fine. So I cannot find any error in this code that makes it loop itself. (If the problem isn't in this code then the looping code it beneath it)
def thebeast(yourhp):
foe = "Thisisirrelevant"
enemy = int(random.randint(1,4))
if enemy == 1:
foe = "skeleton"
elif enemy == 2:
foe = "man with crazy eyes"
else:
foe = "dog, a big and scary dog"
monsteract = 1
dmg = 0
print "-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~"
time.sleep(0.1)
print " C O M B A T"
time.sleep(0.1)
print "-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~"
time.sleep(0.1)
print "You encounter a " + foe
time.sleep(0.5)
while monsteract == 1:
comb = str(input("What do you do to the " + foe + "?" + " Do you feel like jabbing it or stabbing it?"))
if comb in ["s", "S", "Stab", "STAB", "stab"]:
if spear == 1:
dmg = int(random.randint(1,4))
elif sword == 1:
dmg = int(random.randint(1,3))
else:
dmg = int(random.randint(1,5))
elif comb in ["j", "J", "Jab", "JAB", "jab"]:
if spear == 1:
dmg = int(random.randint(1,3))
elif sword == 1:
dmg = int(random.randint(1,4))
else:
dmg = int(random.randint(1,5))
if dmg == 1:
print "You slay the " + foe + " with graceful ease"
time.sleep(0.5)
monsteract = 0
else:
enemydmg = int(random.randint(1,3))
print "The " + foe + " strikes you for " + str(enemydmg) + " damage"
time.sleep(0.3)
print "That didn't work out as planned, but you pull yourself together and prepare to strike the " + foe
time.sleep(0.3)
yourhp = yourhp - enemydmg
if yourhp < 0:
yourhp = 0
print "You have " + str(yourhp) + " health left"
time.sleep(0.3)
if yourhp < 1:
print "The " + foe + " has slain you, well done, you're dead, on the bright side the innocent "
print foe + " is still alive! Every life counts, even that of a " + foe + "."
monsteract = 0
return thebeast(yourhp)
Looping code:
def randomevents(yourhp):
turn = 10
while turn > 0:
time.sleep(0.1)
happening = int(random.randint(1,6))
time.sleep(0.1)
if yourhp < 1:
turn = 0
print "You managed to escape the dungeon, by dying that is"
elif happening == 1:
turn = turn - 1
thebeast(yourhp)
elif happening == 2:
item(sword, spear)
turn = turn - 1
elif happening in [3, 4, 5]:
friend()
turn = turn - 1
print "Well done! You escaped the dungeon! (Either by running out of it, or by having your soul sent to another world)"
useless = str(input("Are you satsified with yourself?: "))
Thank you!
Look at your return statement at the end of thebeast. At the end of the function, you call the function again! Since this happens every time you call it, you will never stop calling it (until you hit the maximum recursion depth). Considering that you don't capture the return value of thebeast in randomevents, you should consider it not returning anything.

Why won't values between 100 and 1000 work when playing Four is Magic, excluding values by 100

Everything works besides values between 100 and 999, except values divisible by 100 work.
The game is as follows:
Four is magic. Write a Python program (called q3.py) that given an integer from 0 to 1000 does the “4 is magic” transformation. The steps are as follows:
Convert the integer n into English and count the number of letters (i.e. 21 is “twenty one” and consists of 9 letters, 102 is “one hundred two” and consists of 13 letters, 1000 is “one thousand” and consists of 11 letters).
Let nlen be the length of the English word equivalent for the integer n.
a. If nlen is 4, output “four is magic.” Then, terminate the transformation process.
b. Otherwise output “ is nlen.” Repeat
step (a), where the integer n is set to nlen.
Suppose the user inputs the integer 26. Then, the transformation proceeds as follows.
26 is 9. , where twenty six is the 9-letter English word equivalent of 26.
9 is 4. , where nine is the 4-letter English word equivalent of 9.
4 is magic.
def convert(number_str):
# Enter your code here.
count = 0
index = 0
x = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
y = ['zero','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
while (number_str != '4'):
if 0 <= int(number_str) <= 19:
a = len(x[int(number_str)])
print(x[int(number_str)],'is',a)
number_str = str(a)
elif 20 <= int(number_str) <= 99:
if number_str[1] == "0":
a = len(y[int(number_str[0])])
print(y[int(number_str[0])],'is',a)
number_str = str(a)
else:
a = len(y[int(number_str[0])]) + len(x[int(number_str[1])])
print(y[int(number_str[0])] + ' ' + x[int(number_str[1])],'is',a)
number_str = a
elif 100 <= int(number_str) <= 999:
rem = int(number_str) % 100
div = int(number_str) // 100
if rem == 0:
a = len(x[div]) + 7
print(x[div] + ' hundred is',a)
number_str = str(a)
else:
if (number_str[1] == '0'):
a = len(x[div]) + 7 + len(convert(str(rem)))
print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
number_str = str(a)
elif (number_str[1] != '0'):
a = len(x[div]) + 6 + len(convert(str(rem)))
print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
number_str = str(a)
elif number_str == '1000':
a = 11
print('one thousand is '+ str(a))
number_str = str(a)
return 'four is magic'
def main():
''' The program driver. '''
user_input = input('> ')
while user_input != 'quit':
print(convert(user_input))
user_input = input('> ')
main()
My question is what is wrong with this area:
else:
if (number_str[1] == '0'):
a = len(x[div]) + 7 + len(convert(str(rem)))
print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
number_str = str(a)
elif (number_str[1] != '0'):
a = len(x[div]) + 6 + len(convert(str(rem)))
print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
number_str = str(a)
convert always returns "four is magic" It looks like you want it to return some value based on its input.
def convert(number_str):
# Enter your code here.
count = 0
index = 0
x = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
y = ['zero','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
while (number_str != '4'):
if 0 <= int(number_str) <= 19:
a = len(x[int(number_str)])
print(x[int(number_str)],'is',a)
number_str = str(a)
elif 20 <= int(number_str) <= 99:
if number_str[1] == "0":
a = len(y[int(number_str[0])])
print(y[int(number_str[0])],'is',a)
number_str = str(a)
else:
a = len(y[int(number_str[0])]) + len(x[int(number_str[1])])
print(y[int(number_str[0])] + ' ' + x[int(number_str[1])],'is',a)
number_str = a
elif 100 <= int(number_str) <= 999:
rem = int(number_str) % 100
div = int(number_str) // 100
print(div)
if rem == 0:
a = len(x[div]) + 7
print(x[div] + ' hundred is',a)
number_str = str(a)
else:
if (number_str[1] == '0'):
a = len(x[div]) + 7 + len(str(x[rem]))
print(x[div] + ' hundred ' + str(x[rem]) + ' is '+ str(a)) # error was here
number_str = str(a)
elif (number_str[1] != '0'):
a = len(x[div]) + 6 + len(str(x[rem]))
print(x[div] + ' hundred ' + str(x[rem]) + ' is '+ str(a)) # error was here
number_str = str(a)
elif number_str == '1000':
a = 11
print('one thousand is '+ str(a))
number_str = str(a)
return 'four is magic'
def main():
''' The program driver. '''
user_input = input('> ')
while user_input != 'quit':
print(convert(user_input))
user_input = input('> ')
main()
Where I commented #error you were doing recursion which was not what you wanted ( I think). But fixed it and it should work now. When you call recursive functions (calling the same function) it execute the newest call on the stack, returning the value it came back with, which isn't how your program worked.
Also I noticed you weren't calling x[rem] like you were suppose to for a look up on the spelling, fixed that too.
Next time please include desired output instead of making us fish for information.

Why is my list index out of range?

def main():
print("You haved activated Weather Pro 3.0")
rain_inputs()
rain_calc()
def rain_inputs():
global rain
rain = []
for x in range(1, 13):
try:
rain_meter = float(input("What is the rainfall? "))
rain.append(rain_meter)
if x == 4:
print("8 more months to go!")
elif x == 7:
print("5 more months to go!")
elif x == 9:
print("2 more to go! Smash those keys!")
elif x == 13:
return
except Exception as err:
err = ("You should be putting in numbers!")
print(err)
rain_calc is supposed to calculate the total of all listed inputs.
def rain_calc():
rain_math =(rain[0] + rain[1] + rain[2] + rain[3])
rain_math2 =(rain[5] + rain[6] + rain[7] + rain[8])
rain_math3 =(rain[9] + rain[10] + rain[11] + rain[12])
rain_total =(rain_math + rain_math2 + rain_math3)
print(rain_total)
main()
The error occurs in rain-math3:
Programming/RainFall.py", line 30, in rain_calc rain_math3 =(rain[9] + rain[10] + rain[11] + rain[12])
IndexError: list index out of range
rain[12] is out of range because rain only has 12 elements in it. You missed rain[4], so you probably wanted this:
def rain_calc():
rain_math =(rain[0] + rain[1] + rain[2] + rain[3])
rain_math2 =(rain[4] + rain[5] + rain[6] + rain[7])
rain_math3 =(rain[8] + rain[9] + rain[10] + rain[11])
rain_total =(rain_math + rain_math2 + rain_math3)
print(rain_total)

Categories

Resources