1

i am trying to do a uni assignment and i keep getting the invalid syntax error, the error is on line 12 on the "<=", it's like this:

fight = input('fighter name:')
weight = int(input('fighter weight:'))

print('given name:{}'.format(fight))
print('given weight:{}'.format(weight))

while weight != 0 or 'end':
    if weight <= 65:
        print('{} is of the lightweight category.'.format(fight))
        input('fighter name:')
        int(input('fighter weight:'))
    elif weight >= 66 and <= 72:
        print('{} is of the medium weight category.'.format(fight))
        input('fighter name:')
        int(input('fighter weight:'))
    elif weight >= 73:
        print('{} is of the heavyweight category.'.format(fight))
        input('fighter name:')
        int(input('fighter weight:'))
    else:
        print("invalid weight.")
        input('fighter name:')
        int(input('fighter weight:'))

i do not understand why i'm getting this error, help would be appreciated.

CMM
  • 31
  • 2
  • `weight != 0 or WEIGHT == 'end':` `weight >= 66 and WEIGHT <= 72:` – lllrnr101 Apr 29 '21 at 00:57
  • 1
    weight = 'end' will fail when converting to int. – lllrnr101 Apr 29 '21 at 00:58
  • 1
    Remember you're talking to a computer, not a human. The computer doesn't understand the context of "you said 'weight' earlier so it's implied here". It needs to be told explicitly at every turn and makes no such assumptions. – Silvio Mayolo Apr 29 '21 at 00:58
  • 1
    This error is not caused by a typo: let's not vote to close it for that reason. – nicomp Apr 29 '21 at 01:06
  • Why do you have `input('fighter name:')` and `int(input('fighter weight:'))` on their own? Did you mean to put `fight = input('fighter name:')` and `weight = int(input('fighter weight:'))`? And why are they in each of the if-blocks instead of just at the end of the loop? – wjandrea Apr 29 '21 at 01:12
  • BTW, welcome to Stack Overflow! Check out the [tour], and [ask] if you want tips. – wjandrea Apr 29 '21 at 01:12
  • Similar: [How to test multiple variables against a single value?](https://stackoverflow.com/q/15112125/4518341), [Why does `a == x or y or z` always evaluate to True?](https://stackoverflow.com/q/20002503/4518341) – wjandrea Apr 29 '21 at 01:15

1 Answers1

3

Two things:

  • Change your while condition to while weight != 0 or weight == 'end':
  • Change your weight criteria to elif 66 <= weight <= 72:

You can't "chain" and like you think, you have to specify the variable.

bananafish
  • 2,877
  • 20
  • 29