2016-10-17 28 views
-4

Question:如何讓我的Python程序通過在線評分系統?

  • The hand is displayed.
    • The user may input a word or a single period (the string ".") to indicate they're done playing
    • Invalid words are rejected, and a message is displayed asking the user to choose another word until they enter a valid word or "."
    • When a valid word is entered, it uses up letters from the hand.
    • After every valid word: the score for that word is displayed, the remaining letters in the hand are displayed, and the user is asked to input another word.
    • The sum of the word scores is displayed when the hand finishes.
    • The hand finishes when there are no more unused letters or the user inputs a "."
hand: dictionary (string -> int) 
    wordList: list of lowercase strings 

我想爲我的Python編程在線課程編寫代碼。不過,我得到一個錯誤:

ERROR: Failed to display hand correctly - be sure 'Current Hand' and the display of the hand are on the same line!

這裏是我的代碼:

def playHand(hand, wordList, n): 
    total = 0 
    while True: 
     print("\nCurrent Hand:",) 
     displayHand(hand) 
     entered = input('Enter word, or a "." to indicate that you are finished: ') 
     if entered == '.': 
      print ("Goodbye! Total score: " + str(total) +" points.") 
      break 
     if isValidWord(entered, hand, wordList) == False: 
      print ("Invalid word, please try again.") 
     else: 
      total += getWordScore(entered, n) 
      print (str(entered), "earned", getWordScore(entered,n), "points. Total:", str(total)) 
      hand = updateHand(hand, entered) 
     if calculateHandlen(hand) == 0: 
      print ("\nRun out of letters. Total score: " + str(total) +" points.") 
      break 
+0

我們不能幫忙,因爲顯然你沒有發佈你的所有代碼。無論你做了什麼後,「無法顯示手」顯示。 –

+0

@MarcB大概是來自某種自動化評分系統(看起來像MIT 6.00x)。也就是說,他們不顯示例如'displayHand'。 – jonrsharpe

+0

@jonrsharpe:也許。但是無論如何,沒有爲'displayHand'或'isValidWord'等給出的代碼...... –

回答

0

答案就在你的代碼已經:

def displayHand(hand): 
    for letter in hand.keys(): 
     for j in range(hand[letter]): 
      print(letter,end=" ")  # print all on the same line 
    print()        # print an empty line 

使用結束=」「在您的打印聲明!!