If the first argument is x and second argument is n then your script is expected to display the nth digit of x after the decimal point. The script should display a message if n is outside the range and exit elegantly. If the number of arguments is less than 2, then too the script should display an appropriate message and exit properly. trying in sage math jupyter notebook
import sys if len(sys.argv) < 3: print("Usage: python assn2a.py {pi/e} n") sys.exit(1)
x = sys.argv[1] n = int(sys.argv[2])
if n < 1 or n > 200: print("n should be an integer between 1 and 200.") sys.exit(1)
if x == "pi": value = str(pi) elif x == "e": value = str(e) else: print("Invalid value for x. Please choose 'pi' or 'e'.") sys.exit(1)
digit = value.split(".")[1][n-1]
print(digit)