def checkFizzBuzz(fizz = []): count = 1 for x in fizz: if(type(x).__name__ == "int"): if((x > 0) and (x < 101)): if(x == count): print "Line " + str(count) + ": " + str(x) + " - PASS" count += 1 else: print "Line " + str(count) + ": " + str(x) + " - FAIL" count += 1 if(type(x).__name__ == "str"): if((count % 3 == 0) and (count % 5 == 0 ) and (x == "FIZZBUZZ")): print "Line " + str(count) + ": " + str(x) + " - PASS" count += 1 elif((count % 3 == 0) and (x == "FIZZ")): print "Line " + str(count) + ": " + str(x) + " - PASS" count += 1 elif((count % 5 == 0) and (x == "BUZZ")): print "Line " + str(count) + ": " + str(x) + " - PASS" count += 1 else: print "Line " + str(count) + ": " + str(x) + " - FAIL" count += 1 return; def openFizzBuzz(): f = open("fizzbuzz.txt", "r") fizz = [] for line in f: if(line == "FIZZ\n"): fizz.append("FIZZ") elif(line == "BUZZ\n"): fizz.append("BUZZ") elif(line == "FIZZBUZZ\n"): fizz.append("FIZZBUZZ") else: fizz.append(int(line)) f.close() return fizz; fizz = openFizzBuzz() print "First value in list is of type: " + type(fizz[0]).__name__ print "Last value in list is of type: " + type(fizz[(len(fizz) - 1)]).__name__ print "First test to see if FIZZBUZZ ouput the correct number of entries..." if(len(fizz) == 100): print "100 entries detected: PASS" elif(len(fizz) < 100): print "Less than 100 entries detected: FAIL" elif(len(fizz) > 100): print "More than 100 entries detected: FAIL" print "..." print "..." print "Second test verifies all entries, line by line..." checkFizzBuzz(fizz)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question