mardi 9 juin 2020

Python 3 >>> if float(input()) => 6.375 and =< 12.75 syntax issue - tried Decimal

Python beginner here. I'm having an issue with chaining comparison operators while using floats.

def = calcPdo():
        pdoVal = float(input())

        if pdoVal => 6.375 and =< 12.75:
                print('PDO 1')
        elif pdoVal =>12.76 and =< 28.6875:
                print('PDO 2')
        else:
                print('Invalid - try again')

I try this and get a syntax error at the first =>

I've also tried 'and if', and also reformatting and using 'not > 12.75'

I've also tried to import decimal and get things to work using that, but I get stuck when I try and change getcontext().prec=28 to getcontext().prec=4

Any help would be greatly appreciated. No user input will have more than 4 decimal points.

If it helps at all, the values listed here I'm inputting manually, but I could make items in a list, etc as there are about 100 of them. I've done a bit of Googling, and while I find a few suggestions that come close to what I'm trying to achieve, none quite do it for me.

Thanks,

  • Liam.

Aucun commentaire:

Enregistrer un commentaire