Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use py only Define the is_a_valid_date( ) function which is passed a string date as a parameter. The function returns a boolean indicating whether the

use py only

image text in transcribedimage text in transcribedimage text in transcribed
Define the is_a_valid_date( ) function which is passed a string date as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number for each month (note that February is set to 28 days), e.g. the third element of the month_names list is the month of March and the corresponding third element of the days_in_month list indicates that there are 31 days in March. Notes The parameter string can contain any number of spaces but the month name must always start at the first non-space character from the beginning of the string. The day number part of the date string to be tested could contain alphabetic characters thus making the date string invalid. You will find it useful to use the string method, isdigit ( ), which returns True if a string is made up of digits, False otherwise. Some examples of the function being called are shown below. For example: Test Result print ("1.", is_a_valid_date("January 21") ) 1. True print ("2.", is_a_valid_date("Auust 3") ) 2. False print ("3.", is_a_valid_date(" June 15B ") ) 3. False print ("4.", is_a_valid_date("February 0") ) 4. False print ("5.", is_a_valid_date(" December 3K1") ) 5. False print ("6.", is_a_valid_date("January 28 6") ) 6. FalseDefine the is_a_valid_code( ) function which is passed a string code as a parameter. The function returns a boolean indicating whether the parameter string is a valid code or not. A valid code is a string made up of one letter followed by one or more digits (can also include spaces before, between or after the digits). The first three lines of code inside the function should be: codeletters : [IISII' IIBIIl "N\In a dice rolling game a player's hand is made up of any number of random dice rolls and is valued in the following way: . In this game a run is a sequence of dice values starting from 1, e.g. 123, 12345, 1234, 1. 0 Each dice which is part of a run of dice starting from a 1 has a value which is equivalent to the dice number. The value of any dice which is part of a run is added to the hand score. . If there is no 1 in a hand of dice, the score for the whole hand is 0. o A hand of dice can contain more than one run. Study the following example hands of dice and their corresponding valuation. Make sure you understand how the hands are valued: [5, 3, 2, 5, 4, 5, 6, 4, 3] has value a [3, 4, 1, 5, 3, 1, 4, 6] has value 2 (contains one run with just the dice [1] and a second run with just [1]) [5, 3, 2, 2, 6, 4, 5, 1, 4] has value 21 (contains one run with the dice [1, 2, 3, 4, 5, 6]) [2, 1, 1, 1, 2, 3, 3, 1, 3, 2] has value 19 (contains three separate runs with the dice [1, 2, 3] and a second run [3, 4, 1, 5, 2, 1, 5, 1, 2, 3, 4, 6] has value 37 (contains one run with the dice [1, 2, 3, 4, 5, 6], a second run Define the get_d ice_sco re( ) function which is passed a list of dice rolls called dice_roll_list and returns the value of the hand according to the rules described above. IMPORTANT: your code should not change the parameter list (i.e. you need to make a copy of the parameter list and manipulate the copy). Some examples of the function being called are shown below. For example: print("1:", get_dice_score( [5. print("2:", get_dice_score( [3, print("3:", get_dice_score( [5, print("4:", get_dice_score([2. 1, 3, 21)) print("5:", get_dice_score([3. 1, 2, 3, 4, 6])) print("6:", get_dice_score( l)

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

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions