Posts: 12
Threads: 5
Joined: Jul 2019
so first here is my code.
elif medicin in ("adrenalin", "ad"):
vaegt = int(input("Hvad vejer patienten? ")) #what does the patient weight
dosis_adrenalin = vaegt * 0.01 # Dose to be given
if vaegt >= 50: # if vaegt > 50 give 0,5 mg
print("indgift = 0,5 mg")
print("volumen = 0,5 ml")
else:
if vaegt in (10, 11, 12): #This does nothing
vaegt == 10 # this does nothing
print(f"dosis = {dosis_adrenalin} mg") #it runs this part
print(f"volumen = {dosis_adrenalin} ml")
else:
print("Kan ikke finde medicinen!") i want the code to find the nearest "5"
if vaegt == 12, then I want it to be 10
if vaegt == 13, then I want it to be 15
I want this to go from 10-50. (10, 15, 20, 25 etc.)
Posts: 4,220
Threads: 97
Joined: Sep 2016
vaegt % 5 is how far vaegt is above the next lowest five. So if vaegt % 5 is 0, 1, or 2, you want to subtract vaegt % 5 from vaegt. If vaegt % 5 is 3 or 4, you want to do the same thing, but then add five more.
Posts: 12
Threads: 5
Joined: Jul 2019
(Aug-26-2019, 02:20 PM)ichabod801 Wrote: vaegt % 5 is how far vaegt is above the next lowest five. So if vaegt % 5 is 0, 1, or 2, you want to subtract vaegt % 5 from vaegt. If vaegt % 5 is 3 or 4, you want to do the same thing, but then add five more.
could you give me a code exampel? I dont qiute understand.
Posts: 4,220
Threads: 97
Joined: Sep 2016
Why don't you try to code it? Then I can help you if it doesn't work.
Posts: 12
Threads: 5
Joined: Jul 2019
(Aug-26-2019, 02:34 PM)ichabod801 Wrote: Why don't you try to code it? Then I can help you if it doesn't work. I dont understand the "%"
i could do it like this
elif vaegt in (10, 11, 12):
vaegt = 10
elif vaegt in (13, 14, 15, 16, 17):
vaegt = 15
#repeat but the output I get is messed up.
it would say: dosis = 0,10000000003 mg
what I want is a list ranging from 10-50
list [10, 15, 20, 25, 30, 35, 40, 45, 50] #this is the list
vaegt = int(input("Hvad vejer patienten? ")) #what does the patient weight
to_be_used_veagt = nearest from list #the weight I have to use is the nearest from the list
Posts: 1,838
Threads: 2
Joined: Apr 2017
% is the modulo division operator. That is x % y gives the remainder after dividing x by y :
>>> 4 % 3
1
>>> 4 % 8
4
>>> 4 % 4
0
>>>
Posts: 12
Threads: 5
Joined: Jul 2019
Thanks ichabod801 & ndc85430
That solved my problem.
This must be very simple coding for you. But for me this is an achivement. Cant get my arms down
this is how the outcome is from your help.
vaegt = int(input("Hvad vejer patienten? ")) #what is the weight?
test = vaegt % 5 #the weight must be the nearest "5", so how many times does 5 goes up into the weitht. get the remaining.
print(test) #print the remaining, this will be deleted from the final code.
if test in (1, 2): # if the remaining is 1 or 2
vaegt = vaegt - test #take the weight and subtract 1 or 2
print(vaegt)
elif test in (3, 4): #if the remaining is 3 or 4
vaegt = vaegt - test + 5 #take the weight and subtract 3 or 4 and then add 5
print(vaegt)
Posts: 4,220
Threads: 97
Joined: Sep 2016
(Aug-26-2019, 08:24 PM)d3fi Wrote: But for me this is an achivement. Cant get my arms down
Would your arms be up if we just gave you the code?
Now, here's how I might have done it:
vaegt = int(input('Hvad vejer patienten? '))
remainder = vaegt % 5
vaegt -= remainder
if remainder > 2:
vaegt += 5
|