python - scrabble challenge from openhatch wiki...issue getting the rack -


the area need step 2: link project http://wiki.openhatch.org/scrabble_challenge#step_2:_get_the_rack code far is:

import argparse import sys file=open('sowpods.txt','r') scores = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,      "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,      "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,      "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,      "x": 8, "z": 10}  parser=argparse.argumentparser(description='designed in scrabble') #command line interface using argparse module parser.add_argument("word",help="input letters")#adds argument  description args=parser.parse_args() print(args.word) 

i cant figure out print error message if doesnt input letter, tried doing

if args.word=='':     print('error need letters')     sys.exit() 

but doesnt work. help.

first, make answer optional avoid argparse throwing errors. if no argument passed, set none (or default).

parser=argparse.argumentparser(description='designed in scrabble') parser.add_argument("word",help="input letters", nargs='?')  # nargs args=parser.parse_args()  if args.word none: # check equality none     print('error need letters')     sys.exit() 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -