2014-11-07 6 views
0
#Word Jumble Game 

import random 
import string 

def jumbled(): 
words = ['Jumble', 'Star']#, 'Candy', 'Wings', 'Power', 'String', 'Shopping', 'Blonde', 'Steak', 'Speakers', 'Case', 'Stubborn', 'Cat', 'Marker', 'Elevator', 'Taxi', 'Eight', 'Tomato', 'Penguin', 'Custard'] 
count = 0  
loop = True 
loop2 = True 
while loop: 
word = string.lower(random.choice(words) 
jumble = list(word) 
random.shuffle(jumble) 
scrambled = "".join(jumble) 
while loop2: 
    print '\n',scrambled,'\n' 
    guess = raw_input('Guess the word: ') 
    quit = set(['quit','Quit']) 
    choice = 'quit' 
    if guess.lower() == word:  
     print '\nCorrect!' 
     count+=1 
     print "You took",count,"trie(s) in order to get the right answer",jumbled() 
    else: 
     print '\nTry again!\n' 
     count+=1 
     if count == 3: 
      if words[0]*2: 
       print "It looks like you're having trouble!" 
       print 'Your hint is: %s'(words) # I'm trying to pull a word from the above list here. 



jumbled() 

안녕하세요! 'quit'또는 'Quit'을 입력 할 때마다 게임을 종료하려면 어떻게합니까?'quit'을 입력하여 게임을 어떻게 종료합니까?

기본적으로 나는 혼란스럽고 뒤섞인 단어를 제공하는 프로그램을 만들었습니다. 그런 다음 올바르게 추측해야합니다. 타이핑 할 수있는 기능이 생기면 종료 할 때마다 입력하여 게임을 종료 할 수 있습니다. 사전에

감사합니다! (게임이 어떻게 작동하는지 알 필요가 없습니다. 게임을 끝내면 게임을 종료하는 방법을 찾아야합니다.)

또한 코드를 어디에 입력하여 종료합니까? 만약 당신이 단지 코드를 제공하고 있다면 이것을 설명하십시오.

답변

0
import sys 
guess = raw_input('Guess the word: ') 
if guess in ['quit','Quit']: 
    print "Goodbye!" 
    sys.exit() 

은 참조 : Difference between exit() and sys.exit() in Python

+0

감사합니다. 많은 사랑 – juiceb0xk

+1

왜'guess.trim(). lower() = 'quit''가 끝나기 때문에 끝내야합니까? 또는 'guess.trim(). lower() in ['q ','quit ']' –

+2

우리는 다음을 추가 할 수도 있습니다 : stop, exit, bye, 작별, f *** off, die,^D, i need 지금 가서, GOD QUIT 등의 사랑에 대해, 시험과 제안 사이에 그렇게 할 수있을 것 같아. – Paul

0

당신은 다른 elif 조건을 사용할 수 있습니다.

import sys 
# ... 

if guess.lower() == word:  
    print '\nCorrect!' 
    # ... 
elif guess.lower() == 'quit': 
    sys.exit()  
else: 
    print '\nTry again!\n' 
    # ...