python - Fielding numbers using < and > values -
so wish field these numbers groups can see below, , incorrect , wish know correct method of doing so.
after "if" code assigns rating co-incides score , 1 added counter counts number of groups rating.
#determining meal rating , counting number of applied ratings , priniting def mealrating(score): x in range(0,len(score)): if 1 < , score[x] >3: review[x] = poor p = p + 1 if 4 < , score[x] >6: review[x] = g = g + 1 if 7 < , score[x] >10: review[x] = excellent e = e + 1 print('\n') print('%10s' % ('poor:', p )) print('%10s' % ('good', g )) print('%10s' % ('excellent', e ))
the line
if 1 < , score[x] >3:
just doesn't work. and
connects 2 expressions, reads like
if (1 <) , (score[x] > 3):
and 1 <
meaningless.
a quick fix is
if 1 < score[x] , score[x] > 3:
but looks didn't mean -- after all, checks whether score[x] both greater 1 , greater 3, redundant. meant
if 1 < score[x] , score[x] < 3:
which checks score[x] between 1 , 3, exclusive. there 1 final trick, python allows write in 1 single check as:
if 1 < score[x] < 3:
although if you're comparing several ranges this, may want change either of <
s <=
, because otherwise ranges fail if score[x]
1 of boundaries.
Comments
Post a Comment