विभिन्न प्रकार के एयरक्राफ्ट गिनना
इस अभ्यास के लिए, आपके पास एक dictionary aircraft_engines है जिसमें कुछ लोकप्रिय कमर्शियल हवाई जहाज़ों के इंजन टाइप दिए गए हैं। आप यह गिनना चाहते हैं कि इस डेटासेट में हर इंजन टाइप के कितने हवाई जहाज़ हैं। Python control flow कौशल का उपयोग करते हुए एक for loop बनाएँ, जिसमें if/else स्टेटमेंट हो जो हर नए इंजन टाइप के लिए counts वैरिएबल में 1 जोड़ दे।
यह अभ्यास पाठ्यक्रम का हिस्सा है
MATLAB उपयोगकर्ताओं के लिए Python
अभ्यास निर्देश
- एक for loop लिखें जो
airplane_typesके हर key:value जोड़े से गुजरे। - हर iteration पर, "The x airplane has y engines." प्रिंट होना चाहिए, जहाँ x एयरप्लेन का नाम है और y इंजन का टाइप है।
- हर iteration के लिए,
countsdictionary में संबंधित engine_type key के मान को बढ़ाएँ। - अंत में, "counts" dictionary को प्रिंट करें
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
counts = {}
# Loop over the key:value pairs in airplane_types
for airplane, engine_type in ____.items():
# Print the aircraft name and engine type of each aircraft
print("The {} airplane has {} engines.".format(____, ____))
# Increment the values of the engine_type key in the counts dictionary
if engine_type in counts:
counts[engine_type] = ____[engine_type] + 1
else:
counts[engine_type] = 1
print(____)