[Tutor] Try Exclude and operators
David
bouncingcats at gmail.com
Mon Dec 18 17:58:29 EST 2023
On Mon, 18 Dec 2023 at 22:48, Matt Athome via Tutor <tutor at python.org> wrote:
> Python version
> Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
>
> Purpose
> Give test score for input between 0.0 to 1.0
> Use the try and exclude to throw up a message for invalid user input.
>
> code gives the following error.
> score >= 0 and <= 1.0
> ^^
> SyntaxError: invalid syntax
Hi Matt,
You see a SyntaxError because your syntax is invalid Python.
I hope the below example demonstrates valid syntax that does what you want ...
$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> score = 42
>>> score >= 0 and score <= 1.0
False
>>> 0 <= score <= 1.0
False
>>>
More information about the Tutor
mailing list