phython - 기초 공부 내용 정리(while)

홍준성·2022년 5월 29일
0

python 기초 공부

목록 보기
4/12

while 문은 무한 반복을 할 때 사용하는 것이 좋음(끝을 알 때에는 for문을 쓰고, 아닐 때는 while문을 사용)

qMsg = ("당신의 혈액형은?\n"
		+ "1.A형\n2.B형\n3.O형\n4.AB형\n5.나가기\n"
answer_a = "세심하고 거짓말을 잘 못한다."
answer_b = "거침없고 추진력이 좋다."
answer_o = "사교성이 좋다."
answer_ab = "착하다."
errMsg = "다시 입력해주세요."

while true :
	choice = int(input(qMsg)
    result = ""
    
    if choice == 1:
    	result = answer_a
    elif choice == 2:
    	result = answer_b
    elif choice == 3:
    	result = answer_o
    elif choice == 4:
    	result = answer_ab
    elif choice == 5:
    	break
    else : 
    	result = errMsg
        
    print(result)

       

qMsg = "다음 중 프로그래밍 언어가 아닌 것은?"
choiceMsg = "1.JAVA\n2.python\n3.C언어\n4.망둥어\n"
choice = int(input(qMsg + "\n| + choiceMsg))
answer = 4

//result 값이 정답이 아닐 때만 반복문을 계속 돌리도록 함
while result != "정답!": 
  if choice == answer :
      result = "정답!"
  elif choice >= 1 and choice <=4 :
      result = "오답"
  else:
      result = "다시 시도해주세요"
  print(result)
profile
준성이의 개발자 공부 velog

0개의 댓글