Bob: They told me about this experiment. I'll learn who you are only from the first comment you leave. Hello unknown.
Alice: Hi Bob. I don't think we know each other. I'm in the New Zealand office, Auckland to be precise.
Bob: That's quite a timezone difference. I'm on the other side of the Earth, I just checked.
Alice: Bom dia in Lisbon! Correct? Time passes and we haven't written a single line of code. I start
def main():
pass
Bob: Let's make it a console app
import argparse
def main():
parser = argparse.ArgumentParser(description="TBD")
args = parser.parse_args()
Alice: TBD? Come on.
- parser = argparse.ArgumentParser(description="TBD")
+ parser = argparse.ArgumentParser(description="Think of a number. I'll find it out")
Bob: I'm not sure
args = parser.parse_args()
+ print(guess_number(args))
def guess_number(args):
return 42
Alice: I just checked https://xkcd.com/42/ Presumably not the reason you chose this number. How about this?
import os
def main():
parser = argparse.ArgumentParser(description="Think of a number and I'll find it out")
parser.add_argument("number", nargs="?", type=int, help="Your number if I didn't find it out")
args = parser.parse_args()
guess_number(args.number)
def guess_number(number):
if number is None:
print(42)
else:
clear_screen()
print("Just what I said: {}".format(number))
def clear_screen():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
Bob: How about the usual boilerplate?
import argparse
...
if __name__ == "__main__":
main()
Alice: Mission completed. We’ve written a program together communicating only in code.