저는 Python을 처음 접했고 많은 연습을하고 있습니다. 이것들은 간단한 DiceRoller 중 하나입니다. ATOM에서 완벽하게 작동하지만 IDLE에서 실행하려고하면 문제가 발생합니다. 문제가 발생하는 이유를 파악할 수 없습니다. 확실히 이것은 멍청한 질문입니다. 코드 : 프로그램 후코드는 Python 2가 아닌 Python 3에서 실행됩니다.
import random
dices=[2, 3, 4, 6, 8, 10, 12, 20, 100]
Y= ['yes', 'y']
N= ['no', 'n']
def DiceRoller():
dice_selection=input('Please, choose the dice(d2, d3, etc. - only the number): ')
try:
dice = int(dice_selection)
except ValueError:
print('You have to select a number, try again')
DiceRoller()
if dice not in dices:
print('You have to select a 2, 3, 4, 6, 8, 10, 12, 20, 100 faces dice, try again')
DiceRoller()
number=input('How many dice(s) do you want to roll? ')
try:
numint = int(number)
except ValueError:
print('You have to select a number, try again')
DiceRoller()
ripet=0
while ripet < numint:
ripet += 1
if dice in dices:
result=random.randint(1,dice)
print(result)
else:
Continue()
def Continue():
risposta=input('Do you want to roll again? (Y/N) ')
rispostal= risposta.lower()
if rispostal in Y:
DiceRoller()
elif rispostal in N:
return 'Goodbye'
quit()
else:
print('Please, answer Yes or No')
Continue()
DiceRoller()
오류 오순절 IDLE 내가 다시 (입력 Y 또는 N) 롤하려면 나 한테 물어 : 내가 원하는 경우에 저에게 프로그램 후
Traceback (most recent call last):
File "E:\Corso Python\DiceRoller.py", line 44, in <module>
DiceRoller()
File "E:\Corso Python\DiceRoller.py", line 30, in DiceRoller
Continue()
File "E:\Corso Python\DiceRoller.py", line 33, in Continue
risposta=input('Do you want to roll again? (Y/N) ')
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
오류 오순절 IDLE을 다시 (입력 Y 또는 N)을 출시합니다 :
Traceback (most recent call last):
File "E:\Corso Python\DiceRoller.py", line 44, in <module>
DiceRoller()
File "E:\Corso Python\DiceRoller.py", line 30, in DiceRoller
Continue()
File "E:\Corso Python\DiceRoller.py", line 34, in Continue
rispostal= risposta.lower()
AttributeError: 'list' object has no attribute 'lower'
가 기다려 주셔서 감사합니다!
나는 idle이 python2.7을 돌리고 그 때문에'input'이 오류를 일으킬 것입니다 ... python2.7에서'raw_input'을 사용하고 python3에서'input'을 사용합니다 – Vyko
https://docs.python.org/2/ library/functions.html # input python2에서'input()'에서 반환 된 문자열은 즉시 평가됩니다.이 경우'risposta = y'와 같이 행동하게되고'y '는 처음에는 정의되지 않고'risposta = Y' 여기서'Y'는 두 번째 배열입니다. –
IDLE with Python 3.6.2 – quamrana