mardi 2 janvier 2018

I am doing a Python dice-rolling program but it keeps stuffing up in a certain spot down below

In the def validate_input(str): it keeps saying (SyntaxError: bad input on line 18 in main.py) What is wrong! it works with things like d6, d(int), but can't do 3d6 like (int)d(int). keeps going when you type bad stuff like fwjgdh but i cant do (int)d(int).

import random 
import string
import re
from random import randint

def validator(str1):
    pattern = ("[0-9]*[d][0-9]+")
    vvhile_loop = re.compile(pattern)
    result = vvhile_loop.match(str1)
    if result:
      print (result.groups())
      print ("correct_formatting")
    else:
      print ("incorrect_formattiing")


def validate_input(str):
  if pattern = ("[0-9]*[d][0-9]+"):
    str1.replace("d", "", 1).isdigit()
    return True
  else:
    return False


while True:
  str1 = input("What dice would you like  to roll? (Enter a d)")
  if str1 == "quit" or str1 == "q":
    break
  elif validate_input(str1) and str1.partition("d"):
    one, two, three = str1.partition("d")
    trsuno = str1.replace("d", "", 1)
    another_variable = int(trsuno)
    print (trsuno,random.randint(1, another_variable))
    print (validator(str1))
  elif (str1.isdigit()) != False:
    break
  else:
    print (validator(str1))
    print ("Keep rolling or type quit or q.")
  print ("Would you like to roll another dice?")
  print ("If not, type 'q' or 'quit'.")

print ("EXITING>>>___")




Aucun commentaire:

Enregistrer un commentaire