czahie / cs61a Goto Github PK
View Code? Open in Web Editor NEWStructure and Interpretation of Computer Programs
Home Page: http://inst.eecs.berkeley.edu/~cs61a/fa17/
Structure and Interpretation of Computer Programs
Home Page: http://inst.eecs.berkeley.edu/~cs61a/fa17/
Hi, @czahie. Thank you for sharing solution of hog project! It helps me a lot. But it seems that announce_highest
function in phase2 can not pass the test. Here is the trace back.
>>> # The following function call checks if the behavior of f1 changes,
>>> # perhaps due to a side effect other than printing. The only side
>>> # effect of a commentary function should be to print.
>>> f2_again = f1(11, 1)
# Error: expected
# 1 point! That's the biggest gain yet for Player 1
# but got
Run only this test case with "python3 ok -q 07 --suite 1 --case 1"
---------------------------------------------------------------------
Test summary
0 test cases passed before encountering first failed test case
The bug confused me for hours. I've written the function in another way and it passed the test.
def announce_highest(who, previous_high=0, previous_score=0):
assert who == 0 or who == 1, 'The who argument should indicate a player.'
# BEGIN PROBLEM 7
def say(score0, score1):
nonlocal previous_high, previous_score
if who == 0:
score = score0
elif who == 1:
score = score1
current_score = score - previous_score
if current_score > previous_high:
if current_score == 1:
print("1 point! That's the biggest gain yet for Player", who)
else:
print(current_score, "points! That's the biggest gain yet for Player", who)
return announce_highest(who, current_score, score)
return announce_highest(who, previous_high, score)
return say
# END PROBLEM 7
But I still can't figure out why the first implementation is wrong. I will appreciate it if you can help me.
I think you should check your code in hog item .So much bug in it.Your code can't pass the official test.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.