Question

Thanks to programming experience and language evolution, we have a rather easy fix to this problem....

Thanks to programming experience and language evolution, we have a rather easy fix to this problem. Python has another kind of data type that is exactly applicable here.

Try this example that creates what Python calls a dictionary.

days_in = {'Jan': 31, 'Feb': 28, 'Mar': 31, 'Apr': 30, 'May': 31, 'Jun': 30, 
           'Jul': 31, 'Aug': 31, 'Sep': 30, 'Oct': 31, 'Nov': 30, 'Dec': 31} 

The Python dictionary is actually designed specifically for associative data. See if you can figure out how to fill in this blank:

month_name = input('Abbreviated month name:  ')
month_days = days_in[ Please Enter the Answer Here ]
print(month_name,'has',month_days,'days')

Hint: The values from a dictionary are not chosen by their position within that dictionary, so this is actually much simpler than the earlier question that looked like this.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

days_in = {'Jan': 31, 'Feb': 28, 'Mar': 31, 'Apr': 30, 'May': 31, 'Jun': 30,
           'Jul': 31, 'Aug': 31, 'Sep': 30, 'Oct': 31, 'Nov': 30, 'Dec': 31}
         
month_name = input('Abbreviated month name: ')

# put the input name of the month since name of the month is the key to access month_days
month_days = days_in[month_name]
print(month_name,'has',month_days,'days')

SCREENSHOT:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Thanks to programming experience and language evolution, we have a rather easy fix to this problem....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT