• danaportenier

    Thanks I’ll give it a try. I have just been learning about class methods so will give it a go

    posted in Pythonista read more
  • danaportenier

    Thanks for all of the responses but still seems to have something wrong with variables in my class. I plan to implement mikael’s parsing tips. Brumm even when I use your code exactly I still get the same error listed below.

    Traceback (most recent call last):
    File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py", line 64, in <module>
    primary_bariatric_date.Combined_User_Input_Date()
    File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py", line 59, in Combined_User_Input_Date
    self.year_input, self.month_input, day=1)
    AttributeError: 'User_Input_Date' object has no attribute 'year_input'

    Current code:

    class User_Input_Date():
        def __ini__(self):
    
            self.month_input = input('What was the month (1-12)').strip()
            if self.month_input in ['01', '1', 'Jan', 'January', 'jan', 'january']:
                self.month_input = 1
            elif self.month_input in ['02', '2', 'Feb', 'February', 'feb', 'february']:
                self.month_input = 2
            elif self.month_input in ['03', '3', 'Mar', 'March', 'mar', 'march']:
                self.month_input = 3
            elif self.month_input in ['04', '4', 'Apr', 'April', 'apr', 'april']:
                self.month_input = 4
            elif self.month_input in ['05', '5', 'May', 'may']:
                self.month_input = 5
            elif self.month_input in ['06', '6', 'Jun', 'June', 'jun', 'june']:
                self.month_input = 6
            elif self.month_input in ['07', '7', 'Jul', 'July', 'jul', 'july']:
                self.month_input = 7
            elif self.month_input in ['08', '8', 'Aug', 'August', 'aug', 'august']:
                self.month_input = 8
            elif self.month_input in [
                    '09', '9', 'Sept', 'September', 'sept', 'september'
            ]:
                self.month_input = 9
            elif self.month_input in ['10', 'Oct', 'October', 'oct', 'october']:
                self.month_input = 10
            elif self.month_input in ['11', 'Nov', 'November', 'nov', 'november']:
                self.month_input = 11
            elif self.month_input in ['12', 'Dec', 'December', 'dec', 'december']:
                self.month_input = 12
            else:
                self.month_input = None
            self.year_input = input('What was the year?').strip()
    
        def Combined_User_Input_Date(self):
            combine_date_user_input_month_year = datetime.date(
                self.year_input, self.month_input, day=1)
            return combine_date_user_input_month_year.strftime("%m" + "-" + "%Y")
    
    
    primary_bariatric_date = User_Input_Date()
    primary_bariatric_date.Combined_User_Input_Date()
    

    posted in Pythonista read more
  • danaportenier

    Thanks to all for the help

    posted in Pythonista read more
  • danaportenier

    New coder developing script for use in my day job. Trying to make a class which take user entered month and year and combines them into date object. I can get the code for date entry and parsing into date object working. but then trying to make into a class so I can used over and over in difference instances which I cant seem to get right. I pasted where I currently am in my trial and error. I have been through many iterations trying to make it work. Any advice would be appreciated

    class User_Input_Date():
        def __ini__(self, month_input, year_input):
    
            month_input = input('What was the month (1-12)')
            if month_input in ['01', '1', 'Jan', 'January', 'jan', 'january']:
                month_input = 1
                return month_input
            elif month_input in ['02', '2', 'Feb', 'February', 'feb', 'february']:
                month_input = 2
                return month_input
            elif month_input in ['03', '3', 'Mar', 'March', 'mar', 'march']:
                month_input = 3
                return month_input
            elif month_input in ['04', '4', 'Apr', 'April', 'apr', 'april']:
                month_input = 4
                return month_input
            elif month_input in ['05', '5', 'May', 'may']:
                month_input = 5
                return month_input
            elif month_input in ['06', '6', 'Jun', 'June', 'jun', 'june']:
                month_input = 6
                return month_input
            elif month_input in ['07', '7', 'Jul', 'July', 'jul', 'july']:
                month_input = 7
                return month_input
            elif month_input in ['08', '8', 'Aug', 'August', 'aug', 'august']:
                month_input = 8
                return month_input
            elif month_input in ['09', '9', 'Sept', 'September', 'sept', 'september']:
                month_input = 9
                return month_input
            elif month_input in ['10', 'Oct', 'October', 'oct', 'october']:
                month_input = 10
                return month_input
            elif month_input in ['11', 'Nov', 'November', 'nov', 'november']:
                month_input = 11
                return month_input
            elif month_input in ['12', 'Dec', 'December', 'dec', 'december']:
                month_input = 12
                return month_input
            self.year_input = int(input('What was the year?'))
            self.year_input = year_input
            return year_input
        
        def Combined_User_Input_Date(self, month_input, year_input):
            combine_date_user_input_month_year = datetime.date(year, month, day=1)
            return combine_date_user_input_month_year.strftime("%m" + "-" + "%Y")
            
    primary_bariatric_date = User_Input_Date()
    print(primary_bariatric_date.Combined_User_Input_Date())```

    posted in Pythonista read more
  • danaportenier

    Yes I used that option but was cycling through different option I found to try to be able to call an individual item in my print statement below. Thanks

    posted in Pythonista read more
  • danaportenier

    Sorry for likely simple questions but cant seem to find the answers and the group was awesome with my last simple question. Amazing how much time can be spent looking for answer. Ive certainly spent plenty on this one. Learned a lot in the process of looking but cant find my specific answer

    I just have a simple list and want to use an individual item from the list as an arguement in a function when I call the function.

    Error is “list() takes at most 1 argument (6 given)

    I have tried many variations of this trying to get it correct. Below I have pasted current form of code.

    Abbreviated Code below (weight_lbs and ideal_body_wt are calculated by other functions assigned to a variable and passed to this function):

    percent = list(40, 50, 55, 60, 70, 80)

    def Weight_After_PercentageEWL(percent, weight_lbs, ideal_body_wt):
    x = weight_lbs - (percent * ideal_body_wt)
    weight_after_percentewl = Weight_After_PercentageEWL(percent, weight_lbs, ideal_body_wt)

    print('With Sleeve Gastrectomy patients lose between 40% and 60% Excess Weight Loss. This would put your weight between ' + str(Weight_After_PercentageEWL(percent[0], weight_lbs, ideal_body_wt)) + ' and ' + str(Weight_After_PercentageEWL(percent[3] , weight_lbs, ideal_body_wt)))

    posted in Pythonista read more
  • danaportenier

    Thank you all. I’m embarrassed it was parentheses but guess I dont have a trained enough eye yet

    posted in Pythonista read more
  • danaportenier

    I have been coding for just one month and hate to trouble everyone with this but getting syntax error on the ibw_man and ibw_woman functions. I cant figure out why after exhaustive effort. Any help would be appreciated.

    """Bariatric Math Calculations"""
    
    weight_lbs = int(raw_input('what is your current weight (lbs): '))
    height_ft = int(raw_input('what is your current height in feet: '))
    height_inches = int(raw_input('You are ' + str(height_ft) + ' feet and how many inches: '))
    previous_bariatrics = 0
    
            
    
    def Weight_Convert_Kg(weight_lbs):
        x = weight_lbs / 2.204
        return x
    weight_kg  = int(Weight_Convert_Kg(weight_lbs))
        
    def Total_Height_Inches(height_ft, height_inches):
        x = (height_ft * 12) + height_inches
        return x
    total_height_inches = int(Total_Height_Inches(height_ft, height_inches))
                    
    def Height_Convert_Meters(total_height_inches):
        x = total_height_inches * 0.0254
        return x
    height_meters = Height_Convert_Meters(total_height_inches)
    height_meters = round(height_meters, 2)
        
    
    def Calc_Bmi(weight_kg, height_meters):
        x = weight_kg / (height_meters ** 2)
        return x
    BMI = int(Calc_Bmi(weight_kg, height_meters))
        
    def Weight_Convert_lbs(weight_kg):
        x = weight_kg * 2.204
        return x
    calc_weight_lbs = int(Weight_Convert_lbs(weight_kg)
    
    def Ibw_man (total_height_inches):
        x = 50 + (2.3 *(total_height_inches - 60))
        return x
    ideal_body_wt_man = int(Ibw_man((total_height_inches)) * 2.204
    
        
    def Ibw_woman(total_height_inches): 
        x = 45.5 + (2.3 *(total_height_inches - 60))
        return x 
    ideal_body_wt_woman = int(Ibw_woman((total_height_inches)) * 2.204
    
        
        
    print("kg: ", weight_kg)
    print("inches: ", total_height_inches)
    print("meters: ", height_meters)
    print("bmi: ", BMI)
    print("IBWm: ", ideal_body_wt_man)
    print("IBWw: ", ideal_body_wt_woman)
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!