How can I correct the program which generates random dice rolls

51 views Asked by At
def reject():
  print("get out!")
  quit()
import random
print("chooses random dice rolls")
maximumval=int(input("how many dice rolls do you want?"))
if maximumval<0:
   reject()
else:
    counter=1
    while counter<=maximumval:
        counter=str(counter)
        mydict={
      
         }
         
         val=random.randint(1,7)
         val=str(val)
         mydict.update({counter:val})
         val=int(val)
         counter=int(counter)
        counter+=1
    print(mydict)

it gives parseError on line 17

I was not able to solve it. It says parseError.

1

There are 1 answers

1
noah1400 On BEST ANSWER

Indentation in python is crucial for code blocks. It seems like you have extra spaces in front of all rows between row 17 ( val=random.randint(1,7) ) and 21 ( counter=int(counter) ) including both edges. Remove the extra spaces and you should be good to go.

Fixed code:

def reject():
  print("get out!")
  quit()
import random
print("chooses random dice rolls")
maximumval=int(input("how many dice rolls do you want?"))
if maximumval<0:
   reject()
else:
    counter=1
    while counter<=maximumval:
        counter=str(counter)
        mydict={
      
         }
         
        val=random.randint(1,7)
        val=str(val)
        mydict.update({counter:val})
        val=int(val)
        counter=int(counter)
        counter+=1
    print(mydict)

Consider using an IDE/Text Editor like vscode with the correct extensions this will help you identify such mistakes.