3 개의 입력을 요구하는 간단한 프로그램을 작성 중이며 3 개의 입력이 모두 일치하면 환영 메시지가 인쇄됩니다. (이니셜 == YNH, 나이 == 42, 의사 신참 == 1/27/74).여러 if 문을 파이썬으로 인쇄 하시겠습니까?
또한 사용자 이름 (YoungNathanHeather)의 길이와 3 개의 다른 문자열 중 하나를 인쇄하는 입력 (색상)이 인쇄됩니다.
파란색, 분홍색 및 노란색을 입력 할 때 변수 (색)가 다른 경우에도 세 개의 if 문이 모두 true이고 해당 문자열이 인쇄되는 문제가 있습니다.
어쩌면 여기서 if 문을 여러 개 중첩시켜 놓은 거대한 누락 된 부분이있을 수 있습니다. 그러나 누군가 여기에 무슨 일이 일어나고 있는지 아이디어가 있습니까? 나는 "Yellow"를 입력하고 오직 하나의 문자열 프린트만을 볼 것을 기대한다.
if color == 'blue' or 'Blue':
이 해석이야 당신이 말하는
#checks if inputted information matches criteria.
#if all inputted information matches variable criteria
#(Initials == YNH, Age == 42, DOB == 1/27/74), then
#prints a Welcome message for the user.
if Initials == 'YNH':
if Age == '42':
if DOB == '1/27/74':
print('Welcome Young Nathan Heather')
print('Did you know that your name has ' +str((len('YoungNathanHeather'))) +' letters.')
#Asks for a color and prints a response based on if the color is pink, yellow, or blue
color = input("If you could describe your mood in a color, what would it be ?")
if color == 'blue' or 'Blue':
print('According to my research Master, Blue and Yellow together makes green. Green seems to be equal to money.')
elif color == 'pink' or 'Pink':
print('According to my research Master, Pink attracts women or makes a human into a women. Whatever comes first.')
elif color == 'yellow' or "Yellow":
print('According to my research Master, Yellow indicates a "mellow" mood. Prolong this mood if feasible.')
else:
print("My apologies Master. My research is shallow and I am not yet familiar with that mood's \"color\"")
else:
print('Sorry, Wrong Credentials Entered')
else:
print('Sorry, Wrong Credentials Entered')
else:
print('Sorry, Wrong Credentials Entered')
'SIVABALANs-MBP : Desktop siva $ python test.py Young Nathan Heather에 오신 것을 환영합니다. 귀하의 이름은 18 자라고 알고 계셨습니까? 당신의 기분을 색깔로 표현할 수 있다면, 그것은 무엇입니까? yellow 색깔은 : 노란색 나의 연구 주인에 따르면, 푸른 색과 노란색은 함께 녹색을 만듭니다. 녹색은 돈과 같은 것처럼 보입니다. SIVABALANs-MBP : Desktop siva $'예상 한 결과는 무엇입니까? – Siva