1
저는 Python3 코딩의 초보자입니다. 여기에 문제가 있습니다. 14 번 줄에서는 "n"을 "다시 시도 하시겠습니까?"라고 대답하는 부분에 "Thank you! Goodbye"라고 인쇄하여이 프로그램을 끝내려고했습니다. 그러나 그 아래에 "중단"을 삽입 했더라도 처음부터 다시 시작할 것이라고 밝혀졌습니다. 이제 제가 풀 수있는 유일한 해결책은 전체 프로그램을 sys.exit(0)
으로 끝내는 것입니다. 그러나 전체 프로그램을 종료하기 때문에 이상적인 솔루션이라고 생각하지 않습니다.프로그램 (Python)을 종료하는 방법은 무엇입니까?
import sys
while True:
x=int(input("Enter the coins you expected="))
f=int(input("Enter first coin="))
while f!=1 and f!=5 and f!=10 and f!=25:
print("invalid number")
f=int(input("Enter first coin="))
if x>f:
while x>f:
n=input("Enter next coin=")
if not n:
print("Sorry-you only entered",f,"cents")
again=input("Try again (y/n)?=")
if again=="y":
True
elif again=="n":
print("Thank you, goodbye!")
sys.exit(0)
break
while int(n)!=1 and int(n)!=5 and int(n)!=10 and int(n)!=25:
print("invalid number")
n=input("Enter next coin=")
f=f+int(n)
귀하의 질문에 답변 되었습니까? – Adi219
예, 제 질문에 답변 해주었습니다 :)! –