entire final code

The Subprograms are described below. I was in charge of completing Subprogram 2 and 3. One large difficulty I encountered was within Subprogram 2. I was unable to extract the original txt file and turn it into a list. After deliberating for a while, I found a solution.

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e4424d9a-7b11-4fd1-bc60-4fd1fd78d0d3/640px-Python-logo-notext.svg.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e4424d9a-7b11-4fd1-bc60-4fd1fd78d0d3/640px-Python-logo-notext.svg.png" width="40px" /> Python

</aside>

<aside> ✅ Resources may come in the form of websites, databases, lectures slides, or even people. When given access to a large variety, make use of all of them.

</aside>

<aside> 👥 Collaboration

</aside>

import math

#Subprogram 1 - Minimum allowable implant stem diameter under described loading scenario, Ashvikka Baskaran
def min_stem_dia(body_weight, canal_diameter, ult_ten_strength, outer_dia, canal_offset, stem_dia):
    while True:
        load = 3.25*body_weight
        M = load*canal_offset
        y = 0.5*stem_dia
        I = (math.pi/64)*(stem_dia**4)
        area = (math.pi/4)*(stem_dia**2)
        bending_stress = (M*y)/I
        axial_stress = load/area
        app_ten_stress = bending_stress - axial_stress
        app_ten_stress = round(app_ten_stress)
        if app_ten_stress == ult_ten_strength:
            print("Patient:Ke Huy-Quan:\\n\\tBody Weight:\\t\\t\\t", body_weight, "\\n\\tCanal Diamater:\\t\\t\\t", canal_diameter, "\\n\\tUltimate Tensile Strength:\\t", ult_ten_strength, "\\n\\tMinimum Stem Diameter:\\t\\t", round(stem_dia, 1), "\\n\\tApplied Tensile Stress:\\t\\t", app_ten_stress)
            break
        elif app_ten_stress > ult_ten_strength:
            stem_dia = stem_dia + 0.0001
        elif app_ten_stress < ult_ten_strength:
            stem_dia = stem_dia - 0.0001

#Subprogram 2 - Fatigue life for our implant design, Helen Peng         
with open('SN Data - Sample Metal.txt') as  f:
    sncurve = f.readlines()

def fatigue_life(body_weight,stem_dia,sncurve):
    stress_max = (12*body_weight)/(math.pi*(stem_dia**2)/4)
    #stress_min = -stress_max
    #the tensile stress amplitude is equal to (stress_max - stress_min)/2
    #therefore stress_amp = (stress_max - (-stress_max))/2 = stress_max
    stress_amp = stress_max    
    index_pair = 0
    #evaluate the function the number of times as there are pairs of S and N
    for pair in sncurve:
        #turn the pair corresponding to the index into a list of two numbers, corresponding to S and N
        nx2list = sncurve[index_pair]
        #since the pair still contains \\t and \\n, using replace, those will be removed
        for value in (("\\t", " "), ("\\n", "")):
            nx2list = nx2list.replace(*value)
        li = nx2list.split(" ")
        sncurve_S = float(li[0])
        sncurve_N = int(li[1])        
        Kn = 8.5 + (math.log(sncurve_N,(10)))**((0.7*3)/40)
        stress_fail = Kn*stress_amp
        if (sncurve_S < stress_fail):
            cycles_fail = sncurve_N
            print('The number of cycles at which failure of the implant is expected to occur is: ', cycles_fail)
            print('The corresponding adjusted stress amplitude is: ', round(stress_fail,2))
            return stress_fail
        elif(index_pair > (len(sncurve)-1)):
            print('There is no max stress')
        else: 
            index_pair += 1

#Subprogram 3 - Number of years post-implantation before there is risk of femoral fracture, Helen Peng         
def post_implant_years(modulus_bone,modulus_implant):    
    stress_comp = (30*9.8*111)/(math.pi*(16**2)/4)
    stress_reduc = stress_comp*(3*modulus_bone/(modulus_bone + modulus_implant))**(1/3)
    E_ratio = (modulus_implant/modulus_bone)**(1/2)
    #define the original values as when the number of years since implantation is 0
    #x = 0 while y is equal to 168.54 as it is the remainder   
    x = 0
    y = 168.54    
    print('Number of Years\\tCompressive Strength')
    #while the compressive strength is lower than the stress reduced, the equation will keep showing years post implant
    while y > stress_reduc:
        y = 0.0015*x**2 - 3.752*x*E_ratio + 168.54
        x += 1
        print('\\t',x, ' \\t\\t', round(y,2))
    #once the compressive strength (y) is less than the stress reduced, it will exit the loop and print the final statement
    comp_strength = y
    yrs_fail = x
    print('Since ', round(comp_strength,2), ' is less than ', round(stress_reduc,2), ',there are ', yrs_fail, ' years post-operation until failure') 

#Main Menu and Function, Ashvikka Baskaran
def mainMenu():
    print("Program Menu:")
    print("\\t1. Subprogram 1")
    print("\\t2. Subprogram 2")
    print("\\t3. Subprogram 3")
    print("\\t4. Exit from program")
    selection = int(input("Enter Choice: "))
    
    team_number = 3
    body_weight = 111*9.8
    outer_dia = 29
    canal_diameter = 16
    canal_offset = 49
    modulus_bone = 20.7 #<https://pubmed.ncbi.nlm.nih.gov/8429054/>
    ult_ten_strength = 1515 #Cobalt Chromium Alloy
    modulus_implant = 220 #Cobalt Chromium Alloy
    stem_dia = 0.8*canal_diameter
    
    #Home Menu
    if selection == 1:
        min_stem_dia(body_weight, canal_diameter, ult_ten_strength, outer_dia, canal_offset, stem_dia)
        anykey = input("Click the Enter or Return key to return to the main menu")
        mainMenu()
    elif selection == 2:
        fatigue_life(body_weight,stem_dia,sncurve)
        anykey = input("Click the Enter or Return key to return to the main menu")
        mainMenu()
    elif selection == 3:
        post_implant_years(modulus_bone,modulus_implant)
        anykey = input("Click the Enter or Return key to return to the main menu")
        mainMenu()
    elif selection == 4:
        exit
    else:
        print("Invalid Choice. Enter 1-4")
        anykey = input("Click the Enter or Return key to return to the main menu")
        mainMenu()

mainMenu()