Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to fix my python code! I keep failing test case: leap and no-leap on codepost. Leap: ============================= EXPECTED OUTPUT: The average steps

Please help me to fix my python code! I keep failing test case: leap and no-leap on codepost. Leap: ============================= EXPECTED OUTPUT: The average steps taken in January was 5246.1 The average steps taken in Febuary was 4781.2 The average steps taken in March was 5899.0 The average steps taken in April was 5616.2 The average steps taken in May was 4793.8 The average steps taken in June was 4712.0 The average steps taken in July was 5624.2 The average steps taken in August was 5814.7 The average steps taken in September was 6061.6 The average steps taken in October was 5605.9 The average steps taken in November was 4239.4 The average steps taken in December was 5010.1 ------------------------------------------------------------ ACTUAL OUTPUT: The average steps taken in January was 5,246.1 The average steps taken in February was 4,851.9 The average steps taken in March was 5,777.6 The average steps taken in April was 5,802.1 The average steps taken in May was 4,711.5 The average steps taken in June was 4,792.3 The average steps taken in July was 5,638.2 The average steps taken in August was 5,759.6 The average steps taken in September was 6,114.6 The average steps taken in October was 5,411.0 The average steps taken in November was 4,268.8 The average steps taken in December was 5,138.1 ============================= No leap: ============================= EXPECTED OUTPUT: The average steps taken in January was 5246.1 The average steps taken in Febuary was 4851.9 The average steps taken in March was 5777.6 The average steps taken in April was 5802.1 The average steps taken in May was 4711.5 The average steps taken in June was 4792.3 The average steps taken in July was 5638.2 The average steps taken in August was 5759.6 The average steps taken in September was 6114.6 The average steps taken in October was 5411.0 The average steps taken in November was 4268.8 The average steps taken in December was 5138.1 ------------------------------------------------------------ ACTUAL OUTPUT: The average steps taken in January was 5,246.1 The average steps taken in February was 4,851.9 The average steps taken in March was 5,777.6 The average steps taken in April was 5,802.1 The average steps taken in May was 4,711.5 The average steps taken in June was 4,792.3 The average steps taken in July was 5,638.2 The average steps taken in August was 5,759.6 The average steps taken in September was 6,114.6 The average steps taken in October was 5,411.0 The average steps taken in November was 4,268.8 The average steps taken in December was 5,138.1 ============================= Here is my code: *** steps.py ** def main(): # Declare total months months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] # Total number odd days in each month # February is not a leap year in this data # So take feb = 28 month_days_arr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # Declare index 11 because it count from 0 # So total index value is 12 index = [11] # For loop work from 0 to 11 for i in range(len(index)): try: # try to find out the total number of input month is 12 or not months[index[i]] except TypeError: # When not display the type error print("TypeError: Check month number of days") try: current_month = 0 current_month_days = month_days_arr[current_month] current_month_sum = 0 # reads the file file_handle = open('steps.txt', 'r') while True: for counter in range(current_month_days): line = file_handle.readline() if not line: break current_month_sum += int(line) if not line: break # Use try and except to get the zero division error try: average = float((current_month_sum) / (current_month_days)) # displays the total number of the steps in that year, and an average number of steps taken for each month print( 'The average steps taken in ' + months[current_month] + ' was ' + '{0:,.1f}'.format(float(average))) # ZeroDivisionError. except ZeroDivisionError: # Display if any skipping average steps found print('Skipping average steps taken in ' + months[current_month]) # When current month is less than 11 if current_month < 11: current_month += 1 current_month_sum = 0 current_month_days = month_days_arr[current_month] # except # FileNotFoundError except (IOError, TypeError): # Display file not found print("Error: File not found") # and finally suite to handle the errors: finally: file_handle.close() # Call the main function if __name__ == "__main__": main()

*** steps.txt ***

1102 9236 10643 2376 6815 10394 3055 3750 4181 5452 10745 9896 255 9596 1254 2669 1267 1267 1327 10207 5731 8435 640 5624 1062 3946 3796 9381 5945 10612 1970 9035 1376 1919 2868 5847 685 10578 3477 3937 5994 6971 3011 4474 4344 8068 6564 2659 4064 1161 6830 5167 5686 5352 898 4316 7699 6406 6466 2802 1239 8162 398 9908 8251 8419 6245 8484 9012 6318 853 4031 868 8776 10453 1026 1984 8127 5274 6937 1960 9655 1279 9386 6697 6326 2509 7127 7802 8798 6564 7220 10650 3847 7485 10951 3883 9456 4671 2067 6871 1573 8746 7473 4713 1215 8486 6652 4054 10304 5291 2680 9108 6446 1581 7607 2032 7630 1106 3702 986 8602 556 2209 3055 886 5813 6513 3154 1534 6271 611 4001 6522 3819 8396 2364 9660 5937 2506 9002 8586 8805 552 5802 7825 5610 8169 602 5638 2072 3536 5885 9334 6393 9318 6057 5812 5647 4654 1880 634 3084 9606 2287 3032 4030 5627 1314 8489 1601 8559 2083 5520 1829 2890 4533 3225 7405 3985 5521 1127 7109 8083 3615 1475 2896 10523 7108 797 8443 169 8755 5761 9862 9032 1659 10944 6878 1253 4690 9934 8820 41 9367 1898 3554 10650 3136 3574 9682 3950 691 8247 6677 10381 8879 8660 6431 6030 365 10357 10526 9245 5291 4651 5741 800 540 6074 68 8714 5095 4578 10841 5805 6676 2547 203 10988 604 9057 3787 2397 10984 9807 1703 6382 9793 8592 1279 8005 5297 7166 4070 4252 606 6443 10827 8140 5740 10844 8834 3695 4152 10662 8791 7791 9940 831 2999 2254 1161 808 4233 3562 3301 1530 7387 6425 9907 9752 4533 7079 3305 5286 4313 1503 6501 8201 1723 9501 9878 1844 5976 6171 10265 2607 10667 2310 836 2618 9813 5907 6849 470 8794 528 2327 2200 237 618 4898 1307 3212 1007 1322 10409 6956 8653 3462 3207 9210 1309 4431 9106 7737 1698 1117 3826 5297 5589 3199 9089 5967 3156 5919 2855 5985 1780 6267 6303 9855 3843 1816 2876 5973 2888 709 6509 4320 10342 2616 4887 10470 6084 4573 2457 10205 4627 7927 1703 5034 7042 4292 

*** leapyearsteps.txt ***

1102 9236 10643 2376 6815 10394 3055 3750 4181 5452 10745 9896 255 9596 1254 2669 1267 1267 1327 10207 5731 8435 640 5624 1062 3946 3796 9381 5945 10612 1970 9035 1376 1919 2868 5847 685 10578 3477 3937 5994 6971 3011 4474 4344 8068 6564 2659 4064 1161 6830 5167 5686 5352 898 4316 7699 6406 6466 2802 1239 8162 398 9908 8251 8419 6245 8484 9012 6318 853 4031 868 8776 10453 1026 1984 8127 5274 6937 1960 9655 1279 9386 6697 6326 2509 7127 7802 8798 6564 7220 10650 3847 7485 10951 3883 9456 4671 2067 6871 1573 8746 7473 4713 1215 8486 6652 4054 10304 5291 2680 9108 6446 1581 7607 2032 7630 1106 3702 986 8602 556 2209 3055 886 5813 6513 3154 1534 6271 611 4001 6522 3819 8396 2364 9660 5937 2506 9002 8586 8805 552 5802 7825 5610 8169 602 5638 2072 3536 5885 9334 6393 9318 6057 5812 5647 4654 1880 634 3084 9606 2287 3032 4030 5627 1314 8489 1601 8559 2083 5520 1829 2890 4533 3225 7405 3985 5521 1127 7109 8083 3615 1475 2896 10523 7108 797 8443 169 8755 5761 9862 9032 1659 10944 6878 1253 4690 9934 8820 41 9367 1898 3554 10650 3136 3574 9682 3950 691 8247 6677 10381 8879 8660 6431 6030 365 10357 10526 9245 5291 4651 5741 800 540 6074 68 8714 5095 4578 10841 5805 6676 2547 203 10988 604 9057 3787 2397 10984 9807 1703 6382 9793 8592 1279 8005 5297 7166 4070 4252 606 6443 10827 8140 5740 10844 8834 3695 4152 10662 8791 7791 9940 831 2999 2254 1161 808 4233 3562 3301 1530 7387 6425 9907 9752 4533 7079 3305 5286 4313 1503 6501 8201 1723 9501 9878 1844 5976 6171 10265 2607 10667 2310 836 2618 9813 5907 6849 470 8794 528 2327 2200 237 618 4898 1307 3212 1007 1322 10409 6956 8653 3462 3207 9210 1309 4431 9106 7737 1698 1117 3826 5297 5589 3199 9089 5967 3156 5919 2855 5985 1780 6267 6303 9855 5321 3843 1816 2876 5973 2888 709 6509 4320 10342 2616 4887 10470 6084 4573 2457 10205 4627 7927 1703 5034 7042 4292 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+1. What are the organization's reputation goals on this issue?

Answered: 1 week ago