Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if statement
#1
Hello. hope you can help me.
first. here is my code

medicin = input("hvilken medicin skal du give? ").lower() #What medicine are you giving?
if medicin == "fentanyl":                                  #If the medicine is fentanyl, then ask
    vægt = int(input("Hvad vejer patienten? "))             # what is your weight
    dosis = float(input("Hvilken dosis pr kg vil du give? ")) #what dose per kg do you want to give
    indgift_mikrogram = dosis * vægt                           #dose in micrograms
    indgift_ml = dosis * vægt * 2 / 100                         # dose in ml
    print(f"<Du skal give {indgift_mikrogram} mikrogram")
    print(f"Du skal give {indgift_ml} ml fentanyl")
elif medicin == "midazolam" or "stesolid":                  #If medicin != fentanyl, but == midazolam or == stesolid
    vægt = int(input("Hvad vejer patienten? "))             # weight?
    if vægt < 50:
        dosis_steso = vægt / 5
        indgift_steso = vægt / 5 * 2 / 10
        print(f"Du skal give {dosis_steso} mg")
        print(f"Du skal give {indgift_steso} ml ")
    else:
        print("Du skal give 10 mg - 2 ml")
else:
    print("ikke forstået")                                  # if medicin != fentanyl or midazolam or stesolid
the problem is that if I type anything else than "fentanyl" it jumps to step 10.
I want it to jump to step 18 if medicin != fentanyl or midazolam or stesolid.
I am getting frustrated. I hope there is a simple solution to this.
Reply
#2
https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
elif medicin == "midazolam" or medicin == "stesolid":
Common mistake. Another way to check would be

elif medicin in ["midazolam","stesolid"]:
Reply


Forum Jump:

User Panel Messages

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