Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Created February 26, 2020 21:33
Show Gist options
  • Save bennuttall/b69f90259d3fc76d4952990c45eeed5e to your computer and use it in GitHub Desktop.
Save bennuttall/b69f90259d3fc76d4952990c45eeed5e to your computer and use it in GitHub Desktop.
import sys
def foo(n):
n = int(n)
for i in range(n):
print(i + 1)
if len(sys.argv) > 1:
foo(sys.argv[1])
else:
print("Usage: python3 test.py <n>")
import sys
if len(sys.argv) > 1:
if sys.argv[1] == 'color' and sys.argv[2]:
color = sys.argv[2]
elif sys.argv[1] == 'nocolor':
color = 'white'
else:
print("Usage:")
print("python3 test2.py color red")
print("python3 test2.py nocolor")
import sys
if len(sys.argv) > 1:
if 'aus' in sys.argv:
greeting = "G'day mate!"
elif 'usa' in sys.argv:
greeting = 'Howdy!'
else:
greeting = 'Hello.'
if 'polite' in sys.argv:
seat = 'Please take a seat.'
else:
seat = 'Take a seat.'
print(f"{greeting} {seat}")
else:
print("Usage:")
print("python3 test2.py polite")
print("python3 test2.py aus")
print("python3 test2.py aus polite")
print("python3 test2.py polite usa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment