2012-04-24 2 views
2
#Lab 7-3 The Dice Game 
#add libraries needed 
import random 

#the main function 
def main(): 
    print 

    #initiliaze variables 
    endProgram = 'no' 
    playerOne = 'NO NAME' 
    playerTwo = 'NO NAME' 

    #call to inputNames 
    playerOne, playerTwo = inputNames(playerOne, playerTwo) 

    #while loop to run program again 
    while endProgram == 'no': 
     winnersName = 'NO NAME' 
     p1number = 0 
     p2number = 0 

     #initiliaze variables 

     #call to rollDice 
     winnerName = rollDice(playerOne, playerTwo, winnerName) 

     #call to displayInfo 
     winnerName = displayInfo (winnerName) 

     endProgram = input('Do you want to end program?(Enter yes or no): ') 

#this function gets players names 
def inputNames(): 
    inputNames = string('Enter your names: ') 
    return playerOne, playerTwo  

#this function will get the random values 
def rollDice(): 
    p1number = random.randint(1,6) 
    p2number = random.randint(1,6) 
    if p1number >= p2number: 
     winnerName = playerOne 
    if p1number == p2numer: 
     winnerName = 'TIE' 
    elif winnerName == playerTwo: 
     return winnerName 

#this function displays the winner 
def displayInfo(): 
    print ('The winner is: ', winnerName) 


#calls main 
main() 

初心者のプログラマーで、課題を完了しようとしています。 19行目はエラーを返します。TypeError:inputNames()は引数をとりません(2件)。 19行目:playerOne、playerTwo = inputNames(playerOne、playerTwo)。この行は私の教授によって提供され、私はそれを動作させる方法を理解できません。どんな助けでも大歓迎です!TypeError:inputNames()は引数をとりません(2が指定されています)

+2

を...おそらくそれはあなたが修正できるはずのヒントです。多分それは課題です... –

答えて

2

機能inputNamesは引数を取らない関数として定義されていますが、メソッドのリストにそれを2つの変数を渡している。ここで

はあなたがそれをどのように定義したかである:どのようにここに

def inputNames(): 
    inputNames = string('Enter your names: ') 
    return playerOne, playerTwo 

です

playerOne, playerTwo = inputNames(playerOne, playerTwo) 

あなたが本当に望むものは、プレーヤー1とプレーヤー2の名前を返すことです。その上の行は本当にする必要があります:

playerOne, playerTwo = inputNames() 

と機能は、このような何かローカル二つの名前を収集し、多分、それらを返却する必要があります:それはあなたの教授によってあなたに与えられた場合

def inputNames(): 
    p1 = str(raw_input("Enter the name for player one: ")) 
    p2 = str(raw_input("Enter the name for player two: ")) 
    return p1, p2 
関連する問題