תרגיל list comprehension איתור BMI חריג
- BMI
- Feb 27, 2019
- 1 min read
תרגיל list comprehension איתור BMI חריג
המטרה שלנו היא לכתוב פונקציה, בשורה אחת, המפיקה רשימה של משקלים בין 70-80 ק"ג ורשימה של גבהים בין 160-180 ס"מ ומוצאת רק את הצירוף של משקל וגובה אשר מדד ה-BMI שלו עולה על 30 (וכנראה צריך דיאטה) – הנוסחה למדד BMI משקל לחלק ל- (גובה בריבוע) - הגובה בתצורה של 1.75 מטר.
התוכנית
print([f"{w}kg:{h}cm" for w in range(70,81) for h in range(160,181) if w/(h/100)**2>30 ])
התוצאה
['77kg:160cm', '78kg:160cm', '78kg:161cm', '79kg:160cm', '79kg:161cm', '79kg:162cm', '80kg:160cm', '80kg:161cm', '80kg:162cm', '80kg:163cm']
בתוכנית למעלה כתבנו בשורה אחת, באמצעות list comprehension שמשמעותה- נא להפיק רשימה, והיא מבוצעת באמצעות פתיחה וסגירה של סוגריים מרובעים (זה הכל). בתוך הסוגריים המרובעים השתמשנו ב- format שעזר לנו לשרטט את תצורת הצגת נתוני המשקל והגובה הגדולים מ- 30 זאת עושים באמצעות האות f לפני הציטוט של המחרוזת, כאשר בתוך המחרוזת שתולים משתנים בתוך סוגריים מסולסלים. בנוסף ישנן שתי לולאות for הפועלות להפקת רשימות הגובה והמשקל וכן תנאי if המגביל את מה שאנו רוצים לקבל.
הכל בשורה אחת של קוד.

At PlayPulse.tech, you can find solutions for creating online casinos and gaming platforms. The service offers ready-made technologies that help businesses get started quickly. The website https://playpulse.tech/ contains information about services, including game management, billing, provider integration, and other tools. There is support for cryptocurrencies and the ability to customise the platform for your brand. PlayPulse creates easy-to-use systems so that business owners can focus on players and growth. The solutions are aimed at both beginners and experienced operators in the gambling industry.