파이썬에서 1번, 2번을 끝내야 3번을 할 수 있게 하고 싶습니다.
조회수 844회
메뉴 함수 안에 1, 2, 3, 4의 선택지가 있습니다 1번과 2번의 계산기를 사용해야 3번을 사용하게 하고 싶은데 어떤 코드를 써야할지 잘 모르겠습니다. 코드를 보시면, BMI계산기와 BMR계산기를 쓰지 않으면 3번 Weight Management를 쓸 수 없게 하고 싶습니다.
메인 함수 안에 c_select = 0 c_select2 = 0 이런 식으로 써놓고 2번 elif 부터 if c_select = '1' 3번에는 if c_select2 = '2' 같은 식으로 써도 되는지요...
def main():
user_name, user_birthday, user_gender, weight, height = inputDetails()
bmiCalculator(weight, height)
choice = menu()
while choice not in ['q', 'Q']:
if choice == "1":
bmiValue = bmiCalculator(weight, height)
elif choice == "2":
bmr()
elif choice == "3":
weightManagement()
elif choice == "4":
user_name, user_birthday, user_gender, weight, height = inputDetails()
print("\nInvalid Choice! Please select from the list of choices.\n")
def inputDetails():
print("Introduction and Welcome Message\n")
print("Please input your details below : ")
user_name = input("Name : ")
user_birthday = input("Year of birth (YYYY) : ")
user_gender = input("Gender [F/M] : ")
weight= eval(input("Weight (kg) : "))
height= eval(input("Height (m) : "))
return user_name, user_birthday, user_gender, weight, height
def menu():
print("\nChoose your option below:")
print ("1 - Body Mass Index (BMI) Calculator")
print ("2 - Basal Metabolic Rate (BMR) Calculator")
print ("3 - Weight Management")
print ("4 - Reset user details")
print ("Q/q - Quit")
choice = input ("Your choice?")
return choice
def bmiCalculator(weight, height):
bmiValue = (height*height/weight)
print(bmiValue)
return bmiValue
main()
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
1번과 2번을 호출할때 호출했었는지 체크하는 flag를 추가해주고, 3번을 호출할때 확인해주면 될 것 같습니다.
... if choice == "1": flag_bmi = True elif choice == "2": flag_bmr = True elif choice == "3": if flag_bmi && flag_bmr: weightManagement() ...
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력