dimanche 29 juillet 2018

Beginner getting ValueError

I'm a beginner coder on python trying to make a "die roller" where you can choose the size of die and it returns this error on my 20th line of my code

import sys
import random
import getopt


def main(argv):
    dsize = ''
    try:
        opts, args = getopt.getopt(argv, "hi:o:", ["dsize="])
        except getopt.GetoptError:
        print("Roll.py -d <dsize>")
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('Roll.py -d <dsize>')
            sys.exit()
            # elif opt in ("-d", "--dsize"):
            #  dsize = arg
    print('Die size is ', dsize)
    print('roll is: '(random.randrange(1, dsize)))


if __name__ == "__main__":
    main(sys.argv[1:])

also if i uncomment the "elif opt in", and "dsize" i get this

 File "h:\Projects\Roll.py", line 17
   elif opt in ("-d", "--dsize"):
      ^
SyntaxError: invalid syntax




Aucun commentaire:

Enregistrer un commentaire