Python Forum
UnboundLocalError: local variable ' ' referenced before assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UnboundLocalError: local variable ' ' referenced before assignment
#1
I just cant find the problem here. I have searched for it. but that did not solve my problem.

def fentanyl():    # This one Works
    vaegt = int(input("Hvad vejer patienten? "))
    max_dosis = vaegt * 4
    max_volumen = vaegt * 4 * 2 / 100
    print(f"Du må max total give ptt. {max_dosis} mikrogram, sv. {max_volumen} ml")
    mk_kg = float(input("Hvor mange mikrogram pr. kg. vil du give?  "))
    mk_kg *= vaegt
    dosis = mk_kg * 2 / 100
    print(f"Du skal give {mk_kg} mikrogram")
    print(f"Du skal give {dosis} ml.")

def adrenalin(): #this does not work
    vaegt = int(input("Hvad vejer patienten? "))
    tilbage = vaegt % 5
    vaegt -= tilbage
    if tilbage > 2:
        vaegt += 5
        dosis = vaegt * 0.01
    if vaegt >= 50:
        print("Du skal give 0.5 mg, sv. 0.5 ml!")
    else:
        print(f"Du skal give {dosis} mg, sv. {dosis} ml!")    # It says here that UnboundLocalError: local variable 'dosis' referenced before assignment

def midazolam():    # This does not Work
    vaegt = int(input("Hvad vejer patienten? "))
    tilbage = vaegt % 5
    vaegt -= tilbage
    if tilbage > 2:
        vaegt += 5  #### problemer når den udregner med præcis 13 kg!!!!!!!!!!!!!! #Only note to myself, dont think about this
    dosis = vaegt * 0.2
    ml = dosis * 2 / 10
    if vaegt >= 50:
        print("Giv 10 mg, sv. 2 ml intranasalt!")
    else:
        print(f"Du skal give {dosis} mg, sv. {ml} ml!")

medicin = (input("Hvilken medicin vil du give? "))     
if medicin.lower() in ("fentanyl", "fen", "fenta", "fe"):
    fentanyl()
elif medicin.lower() in ("adrenalin", "ad", "adre"):
    adrenalin()
elif medicin.lower() in ("midazolam", "mi", "mida"):
    midazolam()
Reply


Messages In This Thread
UnboundLocalError: local variable ' ' referenced before assignment - by d3fi - Sep-03-2019, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,178 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  local varible referenced before assignment SC4R 6 1,525 Jan-10-2023, 10:58 PM
Last Post: snippsat
  How does UnboundLocalError work? deanhystad 3 1,682 Feb-25-2022, 01:21 AM
Last Post: bowlofred
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 1,915 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  Referenced before assignment finndude 3 3,277 Mar-02-2021, 08:11 PM
Last Post: finndude
  exec + subprocess = UnboundLocalError paul18fr 6 3,512 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  ReferenceError: weakly-referenced object no longer exists MrBitPythoner 17 11,555 Dec-14-2020, 07:34 PM
Last Post: buran
  Assignment of non-existing class variable is accepted - Why? DrZ 6 4,277 Jul-13-2020, 03:53 PM
Last Post: deanhystad
  UnboundLocalError: local variable 'figure_perso' referenced before assignment mederic39 2 2,279 Jun-11-2020, 12:45 PM
Last Post: Yoriz
  UnBoundLocalError Seaninho 3 2,697 May-31-2020, 07:22 AM
Last Post: azajali43

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020