diff --git a/ex1/a.py b/ex1/a.py new file mode 100644 index 0000000..ccaba7b --- /dev/null +++ b/ex1/a.py @@ -0,0 +1,4 @@ +import sys + +frase = " ".join(sys.argv[1:]) +print("Hai scritto:", frase) diff --git a/ex1/b.py b/ex1/b.py new file mode 100644 index 0000000..44343a0 --- /dev/null +++ b/ex1/b.py @@ -0,0 +1,25 @@ +import argparse +import sys + +VALORI_AMMESSI = {"toto", "tata", "titi"} + +parser = argparse.ArgumentParser() + +parser.add_argument( + '-t', '--target', + nargs='+', + choices=VALORI_AMMESSI, + help="Specifica da 1 a 3 valori tra: toto, tata, titi.", + required=True +) + +# Esegui parsing +args = parser.parse_args() + +# Verifica massimo 3 valori +if len(args.target) > 3: + print("Errore: puoi fornire **al massimo 3** valori tra 'toto', 'tata' e 'titi'.", file=sys.stderr) + sys.exit(1) + +# Tutto OK +print("Valori accettati:", args.target) diff --git a/ex1/c.py b/ex1/c.py new file mode 100644 index 0000000..4a1a801 --- /dev/null +++ b/ex1/c.py @@ -0,0 +1,10 @@ +import sys +import pyfiglet + +if len(sys.argv) < 2: + print("Usa: python script.py 'testo da convertire'") + sys.exit(1) + +text = " ".join(sys.argv[1:]) +ascii_art = pyfiglet.figlet_format(text) +print(ascii_art)