0
이 코드에 약간의 문제가 있습니다. 내가 2를 입력하여 whaleq()
을 실행하려고하면, 대신에 mathschallenge()
을 실행합니다. 사용자가 1을 입력 할 때만 실행되기를 원합니다.변수를 정의하고 변수 파이썬을 추출합니다
누구든지 모양을 고칠 수 있습니까? 아래 코드는 파이썬 유휴 상태의 코드와 완전히 동일합니다.
print('The first thing you should think about doing is asking the locals if they have seen anything!')
locallist = ['Ann-Marie, the butcher (1)',
'Bella, the flourist (2)',
'Caitlyn, the painter (3)',
'Daniel, the scientist (4)',
'Lauren, the Zookeeper (5)']
print(locallist)
localpick = int(input('Type the number of the local you want to talk to '))
def localx():
if localpick == 1:
mathschallenge()
if localpick == 2:
whaleq()
def mathschallenge():
print('maths challenge yolo')
quest = input('What is 10+10?')
if quest == '20':
print('correct')
else:
print('incorrect')
def whaleq():
mammal = input('What is the largest mammal?')
if mammal == 'whale':
print('correct')
else:
print('incorrect')
input('Press the enter key to exit')
에서 테스트되었습니다. –
정확한 코드가 아니기를 바랍니다. 그것은 들여 쓰기가 적절하지 않습니다. – RvdK
localx를 localpick으로 변경했는데 다른 점이 없습니다. 그리고 @RvdK는 4 개의 공백으로 여기에 들여 쓰는 코드를 붙여 넣어야했습니다. 그래서 꺼져있을 수도 있습니다. –