2015-01-03 2 views
0

안녕하세요. 저는 스크립트 y'now를 만들고 있었는데, 재미 만 있었고 작은 문제가 생겼습니다.def를 사용하는 Python 3.2.0

내 코드가 작동해야하는 방식으로 스크립트를 리콜해야하지만 다른 스크립트를 리콜 할 때 리콜해야합니다.

다소 혼란 스럽지만 스크립트에서 좀 더 의미가 있습니다. 내 코드는 다음과 같습니다.

# Importing time and date... 
import time 
import datetime 

# Defining ans() and name(). 
def ans(): 
    print("Are you sure your name is Vegas?") 
    time.sleep(2) 
    print("Well I'm not so sure.") 
    time.sleep(1) 
    print("You'll have to prove it.") 
    time.sleep(1) 
    print("Which typewriter brand does Vegas have?") 
    print("1. Sizzix") 
    print("2. Royal") 
    print("3. Alivetti") 
    print("4. Smith-Corona") 
    ans=input(">") 
    if ans == "4": 
     print("Correct....") 
    else: 
     print("Incorrect! You are not Vegas! Liar!") 
     name() 

def name(): 
    name=0 
    print("Detecting...") 
    time.sleep(2) 
    name == input("Is your name Vegas? (Y or N) >") 
    if name == "Y": 
     ans() 
    if name == "N": 
     name() 

# Now for the actual script. This prints the time and then runs the code in name(). 
now = datetime.datetime.now() 
print(now, " --That is the time.") 
name() 
# If name == Y, then it's supposed to go to ans() and run the code there. 
# Instead it goes through the code inside name() and then stops. 

큰 글꼴은 모두 메모 (#)로 사용했습니다. 나는 그 이름을 베가스라고 부르는 내 친구를 위해이 대본을 만들고 있었다.

+0

입력하신 내용은 무엇입니까? 입력 한 내용과 콘솔에 표시되는 출력을 첨부 할 수 있습니까? – SMA

+0

정말 감사합니다. – boatofturtles

답변

1

두 개의 오류 :
1. 할당 기호에 유의하십시오.
name = input("Is your name Vegas? (Y or N) >")
대신 가변
방법에서의
name == input("Is your name Vegas? (Y or N) >")

2. 나쁜 이름으로 "이름()"이 할당되는 변수 ("이름 ')의 이름을 변경()의 반환 값에 :
nameVar = input("Is your name Vegas? (Y or N) >")
우리가 이것을하지 않으면, 우리는 오류 :
을 얻을 것이다TypeError: 'str' object is not callable
나는 왜 이런 일이 벌어 졌는지 이미 알고 있다고 생각합니다. (변수 이름과 메소드 이름 사이의 이름 충돌)!

1
name == input("Is your name Vegas? (Y or N) >") 

은 당신이 원하는 것은

name = input(...)

0
name == input("Is your name Vegas? (Y or N) >") 

문제가 여기에있다, 아마 잘못된 것입니다. 그것은해야한다;

name = input("Is your name Vegas? (Y or N) >") 

은, 귀하의 의견은 함수가 절대 처리되지 않는 이유는, 그래서 실제로 귀하의 의견은 항상 거짓입니다 잘못된 것입니다.

관련 문제