[Tutor] input problem ?

Tom Jenkins tjenkins@devis.com
Thu, 06 Sep 2001 17:14:34 -0400


Hi Walter,
Couple of problems here which are easily fixable...

Walter van den Broek wrote:
> Hi, 
> Complete newbie here.
> From a lot of patients we get data to obtain a diagnosis.
> To make it easier and more accurate i planned to put the obtained scores
> in a program to verify the diagnoses.
> From the first two questions at least one has to have a score>4.
> If that is the case from the other 7 questions at least 4 have to score
> higher than four to become diagnosed as being severely depressed.
> I tried the following code to accomplish it, but became slightly
> "depressed"
> At first with the first two questions it worked well, appending the
> other questions delivered error messages
> Traceback (innermost last):
>   File "<string>", line 1, in ?
> SyntaxError: can't assign to operator (dsm4.py, line 10)
> And this is the code:
> import string
> vraag_234 = input ( "Wat is de score bij vraag 234? ")
> vraag_326 = input ("Wat is de score bij vraag 326? ")
> vraag_317-321 = input ("Wat is de score bij vraag 317-321?")
> vraag_272-315 = input ("Wat is de score bij vraag 272-315?")
> vraag_334-343 = input ("Wat is de score bij vraag 334-343?")
> vraag_315 = input ("Wat is de score bij vraag 315?")
> vraag_240-242 = input ("Wat is de score bij vraag 240-242?")
> vraag_325 = input ("Wat is de score bij vraag 325?")
> vraag_246-250 = input ("Wat is de score bij vraag 246-250?")
> 

change the '-' to '_' in these variables...


> if (vraag_234 > 4) or (vraag_326 > 4):
>     print "Er kan sprake zijn van een depressie volgens DSM IV criteria"
> 
> else:
>     print "Er kan geen sprake zijn van een depressie volgens DSM IV
> criteria"
> 
> 
> 
> List = []
> if (vraag_317-321 > 4):
>     List.append
> if (vraag_272-315 > 4):
>     List.append
> if  (vraag_334-343 > 4):
>     List.append
> if (vraag_315 > 4 ):
>     List.append
> if (vraag_240-242 > 4):
>     List.append
> if (vraag_325 > 4):
>     List.append
> if (vraag_246-250 > 4):
>     List.append
> len(List)
> if len(List) > 4:
>     print "Er is sprake van de depressieve stoornis volgens DSM IV
> criteria"
> 
> else:
>     print "Er is geen sprake van een depressieve stoornis volgens DSM IV
> criteria"
> 

Here you really don't need a list; you are counting the number of 
answers that are "positive results" (ie > 4).  so lets just keep a 
running count...

  count = 0
  if (vraag_317_321 > 4):
      count = count + 1
  if (vraag_272_315 > 4):
      count = count + 1
  if  (vraag_334_343 > 4):
      count = count + 1
  if (vraag_315 > 4 ):
      count = count + 1
  if (vraag_240_242 > 4):
      count = count + 1
  if (vraag_325 > 4):
      count = count + 1
  if (vraag_246_250 > 4):
      count = count + 1

  if count > 4:
      print "Er is sprake van de depressieve stoornis volgens DSM IV 
criteria"
  else:
      print "Er is geen sprake van een depressieve stoornis volgens DSM 
IV criteria"



-- 
Tom Jenkins
devIS - Development Infostructure
http://www.devis.com