2014-11-14 4 views
-6

코드는 사용자가 입력 한 직후 yes_or_no 함수 내에서 멈추게됩니다. 오류 메시지가 없습니다. 제발 도와주세요! 당신이 볼 수 있듯이 간단한 구매를 실현하는 것입니다. buy_something 함수를 테스트 할 수 없었고 문제가있을 수 있음을 알고 있습니다.Python에서 RPG 만들기

print "Shopkeeper: So, you interested in anything?" 

당신이 yes를 입력 후 바로 다음이 answer1 = raw_input() 와 원시 입력을 기다리거나 아니, 당신은 item = raw_input()

다시 입력을 기다립니다 어떻게됩니까

#!/usr/bin/env python 

import time 

# Intro 
print "Input Name:" 
time.sleep(1) 
name = raw_input() 
print "Welcome to Tittyland brave %s'" %(name) 
time.sleep(2) 
print "You are given nothing but 500 gold to start you journey..." 
time.sleep(2) 
print "Good luck..." 
time.sleep(3) 
print "Shopkeeper: 'Eh there stranger! Looks like you'll need some gear before going into the wild! Check out my store!'" 
time.sleep(4) 
print "" 

#Inventory and first shop 
inventory = { 
    'pocket' : [], 
    'backpack' : [], 
    'gold' : 500, 
} 

shop = { 
    'dagger' : 50, 
    'leather armor' : 150, 
    'broadsword' : 200, 
    'health potion' : 75, 
} 

#Buying items 
for key in shop: 
    print key 
    print "price: %s" % shop[key] 
    print "" 
print "Shopkeeper: So, you interested in anything?" 

answer1 = raw_input() 
item = raw_input() 

def buying_something(x): 
    for i in shop: 
     if shop[i] == x: 
      inventory[gold] -= shop[i] 
      inventory[backpack].append(shop[i]) 

def yes_or_no(x): 
    if x == 'yes': 
     print "Shopkeeper: 'Great! So what is your desire stranger" 
     buying_something(item) 
    else: 
     print "Shopkeeper: 'Another time then'" 


yes_or_no(answer1) 
+1

"Tittyland에 오신 것을 환영합니다." 어쨌든 두 줄의 입력을 연속해서 읽는 것입니다. 그것은 붙어 있지 않고 두 번째 줄을 기다립니다. – JJJ

+0

일반적으로 재생기는 문제를 설명하는 데 필요한 최소한의 코드로만 구성되어야합니다. 이 경우, 그것은 당신의 전체 프로그램보다는 두 줄과 같을 것입니다. 말하자면, 그것이 붙어있는 곳 일뿐입니다. 자세한 지침은 http://stackoverflow.com/help/mcve를 참조하십시오. –

답변

0

두 기능이 모두 수정되었습니다. raw_inputs의 위치가 잘못되었습니다 :

def yes_or_no(purchase_q): 
    if purchase_q == "yes": 
     while True: 
      things = raw_input("Great. What is your hearts desire(type no more to exit shop): ") 
      if things != "no more": 
       buying_something(things) 
      else: 
       print "Good luck on your journey then" 
       break 


def buying_something(item): 
    if item in shop.keys(): 
     print "You have %s gold available" %(inventory.get('gold')) 
     print "Item Added {0}: ".format(item) 
     backpack_items = inventory.get('backpack') 
     backpack_items.append(item) 
     item_cost = shop.get(item) 
     print "Cost of Item is %s gold coins " %(item_cost) 
     inventory['gold'] = shop.get(item) - item_cost 
+0

정말 감사합니다. –

0

이 줄 끝에서이다 Tt는 막히거나 싫어하지 않습니다.

print "Shopkeeper: So, you interested in anything?" 

answer1 = raw_input() 
item = raw_input() // <-- This is in the wrong place 
yes_or_no(answer1) 

사용자가 작성한 내용은 사용자가 예 또는 아니오 응답 후에 원하는 항목을 입력해야하며 예 또는 아니오에 관계없이 입력해야합니다. item = raw_input()을 yes_or_no 기능으로 옮기는 것이 좋습니다.

def yes_or_no(x): 
    if x == 'yes': 
     print "Shopkeeper: 'Great! So what is your desire stranger" 
     item = raw_input() 
     buying_something(item) 
    else: 
     print "Shopkeeper: 'Another time then'"