function - Simple Logical Error in Python -


lines 12 , 13 of code not affecting program.

current output:

hi 10

hi 10

hola 10

desired output:

hi 10

hi 6

hola 10

the second number in right column of csv output should changed 6, not 10 (due lines 12 , 13) why these lines not having affect?

thanks or ideas.

# -*- coding: utf-8 -*- import csv levels = [["1"], ["2"], ["3"]] def column1logic(self, level, greeting):     self.column1 = "logic worked"     if greeting == ["hola"]:         self.column1 = ["poop"]     else:         self.column1 = self.greeting def column2logic(self, level, greeting): # budget     self.column2 = 10      if level == [2]:          self.column2 = self.column2 * .6 class row(object):     column1 = "name"     column2 = "budget"     greeting = "oh"     def __init__(self, level, greeting):         self.level = level         self.greeting = greeting     def rowentry(self, level, greeting):         column1logic(self, level, greeting)         column2logic(self, level, greeting)         lol = [[self.column1], [self.column2]]         lol[0] = self.column1         lol[1] = self.column2         file_writer.writerow([o o in lol]) open("test.csv", "wb") test_file:     file_writer = csv.writer(test_file)     in range(0, len(levels)):         if levels[a] == ["3"]:             greeting = "hola"             food = row(levels[a], greeting)             food.rowentry(levels[a], greeting)         else:             greeting = "hi"             food = row(levels[a], greeting)             food.rowentry(levels[a], greeting) 

if level == [2]: needs use string '2' rather number 2 condition ever evaluate true. got right if levels[a] == ["3"]: in different line.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -