2014-02-17 3 views
0

나는 프로그래밍에 대한 사전 경험이 없으며 이번 학기에 처음으로 프로그래밍 수업을 듣고 있으며, 내가 잘못하고있는 부분에 대해 도움을 필요로합니다. 여전히 컴퓨터 상대에 추가해야하지만 한 가지 문제는 보류 부분이 때로는 작동합니다. 다시 굴러 보거나 붙잡 으려고 할 때 H를 누르고 있으면 가끔씩 움직이게되고 R은 다시 굴러 가듯이 움직입니다. 어떤 도움이라도 대단히 감사하겠습니다.PIG 주사위 게임에 대한 도움이나 조언이 필요합니다.

이것은 내가 지금까지 무엇을 가지고 :

import random 

p1 = 0 
p2 = 0 

print ("Score" "\tYou :", p1, "\tAI :", p2) 

still_playing = True 
hold_pass_input = False 

while still_playing: 

    while True: 

     p1_turn = input ("Your turn. Hit enter to continue.") 
     p1_score = p1 
     p2_score = p2 
     break 

    while (p1_score >= 0 and p1_score <= 50): 
     die_roll = random.randint (1,6) 

     if die_roll > 1: 
      p1_score = die_roll + p1_score 
      print("Die :", die_roll, "Pot :", p1_score,) 

      hold_pass = input("(R)oll again or (H)old?:").upper() 
      while hold_pass_input == False: 

       if hold_pass in ["r", "R"]==["r", "R"]: 
        hold_pass_input = True 
        break 

       elif hold_pass in["h","H"]==["h","H"]: 
        hold_pass_input = False 
        print ("Score" "\tYou :", p1_score, "\tAI :", p2_score) 
        print("It's the computers turn. Hit enter to continue.") 
        break 

       else: 
        hold_pass_input = False 
        print("Use only R, r, H, h") 
        hold_pass = input("(R)oll again or (H)old?:").upper() 

     elif die_roll <= 1: 
      p1_score = p1_score - p1_score 
      print("Die :", die_roll, "Pot :", p1_score, "Bust") 
      p2_turn = input("It's the computers turn. Hit enter to continue.") 

답변

0

나는 문제가 if-elif-else - 블록 내에있는 생각합니다.

if hold_pass in ["r", "R"]==["r", "R"]: 

의미에서 라인이 동일 할 것, 그래서 in 가능성이 가장 높은, True로 평가 할 키워드 후 비트가 :

if hold_pass in True: 

것은하지 않는

이 작업을 수행 많은 감각.

대신이 일을보십시오 :

if hold_pass in ["r", "R"]: 
오류도 elif -clause에 존재

:

elif hold_pass in["h","H"]==["h","H"]: 

이되어야하는 :

elif hold_pass in ["h","H"]: 
관련 문제