Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indentation
#1
I avoid opening a new thread for indentation problem but I just don't get what is wrong here.

import random
random.seed()

def rollDie():
    return random.choice([1, 2, 3, 4, 5, 6])

def runSim(goal, numTrials):
	total = 0
	for i in range(numTrials):
		result = ''
		for j in range(len(goal)):
			result += str(rollDie())
		if result == goal:
			total += 1
    print('Actual probability =', round(1/(6**len(goal)), 8))
    estProbability = round(total/numTrials, 8)
    print('Estimated Probability =', round(estProbability, 8)) 

runSim('11111', 1000)
Error:
IndentationError: unindent does not match any outer indentation level
is for line 15
print('Actual probability =', round(1/(6**len(goal)), 8))
Reply
#2
I don't get an error from the code as posted, but I'm not sure the forum keeps the white space exactly the same. I would double check for a mix of tab and space indents.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I never use tab, always space.
Reply
#4
Exactly! There isn't any error while executing the code u just posted. I would recommend you to just restart your python IDLE or jupyter notebook whichever u r using and then give it a try.

Regards
Reply
#5
I use Notepad++ and Spyder. Again, I get the same error.
Reply
#6
Have you tried copy-pasting the forum code into a new file and trying that?
Reply
#7
make a copy of this code for testing then in the copy, remove lines 8 through 14 and 16 to the end of the file. see if that runs. if it does then add line back one at a time and see when it starts to fail.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
(Apr-20-2019, 01:26 AM)micseydel Wrote: Have you tried copy-pasting the forum code into a new file and trying that?

Yes and it worked. Still, wanted to have code that works on one specific file for some reason. Well, who cares. :)
Reply
#9
does your system have a tool that shows every raw byte (octet) of a file in some diagnosing form such as octal or hexadecimal like the "od" command on Linux?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
I use Windows 7 and Windows 10. Don't know if it has it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020