Skip to content

Instantly share code, notes, and snippets.

@bennuttall

bennuttall/test.py

Created Feb 26, 2020
Embed
What would you like to do?
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