{}
run-icon
main.py
class VitelliaQuestionnaire: def __init__(self): # Initialize the questionnaire state self.current_step = 0 self.recommendations = None self.form_data = { 'personal_info': { 'name': '', 'age': '', 'gender': '' }, 'lifestyle': { 'outdoor_time': '', 'daily_steps': '', 'exercise_frequency': '' }, 'nutrition': { 'diet_type': '', 'fresh_produce': '', 'fish_consumption': '', 'allergies': '' }, 'sleep': { 'hours_per_night': '', 'night_waking': '', 'fall_asleep': '' }, 'stress': { 'stress_level': '', 'low_mood_frequency': '', 'anxiety_frequency': '' }, 'health_concerns': { 'hair_skin_nails': '', 'joints_inflammation': '', 'digestion': '', 'memory_focus': '', 'cardiovascular': '' }, 'medications': { 'current_medications': '' } } # Define questions structure self.questions = [ { 'title': "Personal Details", 'fields': [ { 'type': "text", 'label': "What's your name?", 'section': "personal_info", 'field': "name" }, { 'type': "number", 'label': "How old are you?", 'section': "personal_info", 'field': "age" }, { 'type': "select", 'label': "How do you describe your gender?", 'section': "personal_info", 'field': "gender", 'options': ["Male", "Female", "Other", "Prefer not to say"] } ] }, { 'title': "Lifestyle", 'fields': [ { 'type': "radio", 'label': "How often do you get outside for fresh air?", 'section': "lifestyle", 'field': "outdoor_time", 'options': ["Rarely", "About 3 times a month", "3-4 times a week", "Daily"] }, { 'type': "radio", 'label': "How many steps do you typically take in a day?", 'section': "lifestyle", 'field': "daily_steps", 'options': ["Fewer than 5,000", "5,000–10,000", "More than 10,000", "Not sure"] }, { 'type': "radio", 'label': "How often do you fit in at least 30 minutes of exercise?", 'section': "lifestyle", 'field': "exercise_frequency", 'options': ["Rarely", "About 3 times a month", "3–4 times a week", "5 or more times a week"] } ] }, { 'title': "Nutrition", 'fields': [ { 'type': "radio", 'label': "Do you follow any particular eating style or diet?", 'section': "nutrition", 'field': "diet_type", 'options': ["None", "Vegetarian", "Vegan", "Pescatarian", "Keto", "Other"] }, { 'type': "radio", 'label': "How often do you eat fresh fruits and vegetables?", 'section': "nutrition", 'field': "fresh_produce", 'options': ["Rarely", "A few times a week", "Once a day", "Multiple times a day"] }, { 'type': "radio", 'label': "How often do you have fish or seafood?", 'section': "nutrition", 'field': "fish_consumption", 'options': ["Never", "Once a month", "Weekly", "Multiple times a week"] }, { 'type': "text", 'label': "Do you have any allergies or intolerances we should know about?", 'section': "nutrition", 'field': "allergies" } ] }, { 'title': "Sleep", 'fields': [ { 'type': "radio", 'label': "On average, how many hours of sleep do you get each night?", 'section': "sleep", 'field': "hours_per_night", 'options': ["Fewer than 5", "5–6", "6–7", "7–8", "More than 8"] }, { 'type': "radio", 'label': "How often do you find yourself waking up in the middle of the night?", 'section': "sleep", 'field': "night_waking", 'options': ["Rarely", "About 3 times a month", "3–4 times a week", "Almost every night"] }, { 'type': "radio", 'label': "How often do you struggle to fall asleep?", 'section': "sleep", 'field': "fall_asleep", 'options': ["Rarely", "Sometimes", "Often", "Almost every night"] } ] }, { 'title': "Stress & Mood", 'fields': [ { 'type': "radio", 'label': "In the past month, how would you describe your overall stress levels?", 'section': "stress", 'field': "stress_level", 'options': ["Low", "Moderate", "High", "Very high"] }, { 'type': "radio", 'label': "How often have you felt low or down for more than two days in a row?", 'section': "stress", 'field': "low_mood_frequency", 'options': ["Rarely", "Once or twice", "Weekly", "Several times a week"] }, { 'type': "radio", 'label': "How often have you felt overwhelmed?", 'section': "stress", 'field': "anxiety_frequency", 'options': ["Rarely", "Sometimes", "Often", "Very often"] } ] }, { 'title': "Health Concerns", 'fields': [ { 'type': "radio", 'label': "Hair, skin, or nail issues", 'section': "health_concerns", 'field': "hair_skin_nails", 'options': ["Rarely or never", "1–2 times a month", "About 3 times a month", "Almost daily"] }, { 'type': "radio", 'label': "Joint pain or stiffness", 'section': "health_concerns", 'field': "joints_inflammation", 'options': ["Rarely or never", "1–2 times a month", "About 3 times a month", "Almost daily"] }, { 'type': "radio", 'label': "Digestive discomfort", 'section': "health_concerns", 'field': "digestion", 'options': ["Rarely or never", "1–2 times a month", "About 3 times a month", "Almost daily"] }, { 'type': "radio", 'label': "Difficulty focusing or brain fog", 'section': "health_concerns", 'field': "memory_focus", 'options': ["Rarely or never", "1–2 times a month", "About 3 times a month", "Almost daily"] }, { 'type': "radio", 'label': "Heart or circulation-related concerns", 'section': "health_concerns", 'field': "cardiovascular", 'options': ["Rarely or never", "1–2 times a month", "About 3 times a month", "Almost daily"] } ] }, { 'title': "Medications", 'fields': [ { 'type': "text", 'label': "Are you currently taking any regular medications?", 'section': "medications", 'field': "current_medications" } ] } ] def calculate_recommendations(self): """Calculate personalized supplement recommendations based on form data.""" supplements = ['Daily Vits', 'Omega 3', 'Vitamin D3', 'Lecithin'] additional_supplements = [] health_concerns = self.form_data['health_concerns'] sleep = self.form_data['sleep'] stress = self.form_data['stress'] if (sleep['fall_asleep'] in ['often', 'almost every night'] or sleep['night_waking'] == 'almost every night' or stress['stress_level'] in ['high', 'very high']): additional_supplements.append('Magnesium') if health_concerns['hair_skin_nails'] in ['about 3 times a month', 'almost daily']: additional_supplements.append('Biotin') if health_concerns['digestion'] in ['about 3 times a month', 'almost daily']: additional_supplements.append('Probiotic Blend') if health_concerns['cardiovascular'] in ['about 3 times a month', 'almost daily']: additional_supplements.append('CoQ10') if health_concerns['memory_focus'] in ['about 3 times a month', 'almost daily']: additional_supplements.append('Ashwagandha') additional_supplements = list(set(additional_supplements)) while len(supplements) < 6 and additional_supplements: supplements.append(additional_supplements.pop(0)) return supplements def handle_input(self, section, field, value): """Handle user input updates.""" self.form_data[section][field] = value.lower() if isinstance(value, str) else value def next_step(self): """Move to the next step or calculate recommendations.""" if self.current_step < len(self.questions) - 1: self.current_step += 1 else: self.recommendations = self.calculate_recommendations() def previous_step(self): """Move to the previous step.""" if self.current_step > 0: self.current_step -= 1 def get_current_question(self): """Get the current question set.""" return self.questions[self.current_step] def get_recommendations(self): """Format and return the final recommendations.""" if not self.recommendations: return None name = self.form_data['personal_info']['name'] greeting = f"Thank you, {name}!" if name else "Thank you!" return { 'greeting': greeting, 'message': "Your responses have helped us understand your lifestyle, nutrition, sleep patterns, stress levels, and health concerns. We've carefully selected these supplements to support your overall wellbeing.", 'supplements': self.recommendations, 'advice': "We recommend taking these supplements daily as part of your wellness routine." } def reset(self): """Reset the questionnaire to initial state.""" self.__init__() def main(): questionnaire = VitelliaQuestionnaire() while not questionnaire.recommendations: current_question = questionnaire.get_current_question() print(f"\n=== {current_question['title']} ===") for field in current_question['fields']: print(f"\n{field['label']}") if field['type'] in ['text', 'number']: value = input("Your answer: ") elif field['type'] in ['select', 'radio']: print("Options:") for i, option in enumerate(field['options'], 1): print(f"{i}. {option}") value = field['options'][int(input("Select option number: ")) - 1] questionnaire.handle_input(field['section'], field['field'], value) questionnaire.next_step() results = questionnaire.get_recommendations() if results: print(f"\n{results['greeting']}") print(f"\n{results['message']}") print("\nYour Personalized Supplement Stack:") for supplement in results['supplements']: print(f"- {supplement}") print(f"\n{results['advice']}") if __name__ == "__main__": main()
Output