ex04 ok
This commit is contained in:
24
d00/ex04/whatis.py
Normal file
24
d00/ex04/whatis.py
Normal file
@@ -0,0 +1,24 @@
|
||||
def check_parity(args: list[str]):
|
||||
if len(args) == 0:
|
||||
return
|
||||
if len(args) > 1:
|
||||
print("AssertionError: more than one argument is provided")
|
||||
return
|
||||
|
||||
arg = args[0]
|
||||
try:
|
||||
number = int(arg)
|
||||
except ValueError:
|
||||
print("AssertionError: argument is not an integer")
|
||||
return
|
||||
|
||||
if number % 2 == 0:
|
||||
print("I'm Even.")
|
||||
else:
|
||||
print("I'm Odd.")
|
||||
|
||||
# execute module as a script : https://docs.python.org/3.10/tutorial/modules.html#executing-modules-as-scripts
|
||||
if __name__ == "__main__":
|
||||
# https://docs.python.org/3.10/library/sys.html
|
||||
import sys
|
||||
check_parity(sys.argv[1:])
|
||||
Reference in New Issue
Block a user