Define 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: "T", code_letters = min_for_each_letter = [1, 3, 4, 0, 3] #inclusive max_for_each_letter = [7, 9, 6, 7, 5] #inclusive ["S", "B", "N", "P"] where: • code_letters is the list of code letters which are valid for the first letter of the code string, • min_for_each_letter is a list which contains the minimum possible number (inclusive) for each digit following that letter, • max_for_each_letter is a list which contains the maximum possible number (inclusive) for each digit following that letter. For example, the third element of the code_letters list is the letter 'N', the corresponding third element of the min_for_each_letter list is 4 and the corresponding third element of the max_for_each_letter list is 6. This indicates that the code digits which follows the letter 'N' can be any number made up of the digits 4, 5 or 6. number part of a valid code string can also contain any number of spaces. Note: The number part of a parameter code string to be tested could contain an alphabetic character thus making the code not valid. You will find it useful to use the string method, isdigit(), which returns True if a string is a digit, False otherwise. Some examples of the function being called are shown below. For example: Test Result 1. True print("1.", is_a_valid_code('B747346')) print("2.", is_a_valid_code ( 'N 444 454')) 2. True print("3.", is_a_valid_code('T 400 4854')) print("4.", is_a_valid_code ('S 444S454')) print("5.", is_a_valid_code('P ')) print("6.", is_a_valid_code('T O ')) 3. False 4. False 5. False 6. True

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

use py only 

Define 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:
code_letters
min_for_each_letter
max_for_each_letter
["S", "B", "N", "T", "P"]
%3D
[1, 3, 4, 0, 3] #inclusive
[7, 9, 6, 7, 5] #inclusive
%3D
where:
code_letters is the list of code letters which are valid for the first letter of the code string,
min_for_each_letter is a list which contains the minimum possible number (inclusive) for each digit following that letter,
max_for_each_letter is a list which contains the maximum possible number (inclusive) for each digit following that letter.
For example, the third element of the code_letters list is the letter 'N', the corresponding third element of the
min_for_each_letter list is 4 and the corresponding third element of the max_for_each_letter list is 6. This indicates that the
code digits which follows the letter 'N' can be any number made up of the digits 4, 5 or 6. The number part of a valid code
string can also contain any number of spaces.
Note: The number part of a parameter code string to be tested could contain an alphabetic character thus making the code not
valid. You will find it useful to use the string method, isdigit(), which returns True if a string is a digit, False otherwise. Some
examples of the function being called are shown below.
For example:
Test
Result
print("1.", is_a_valid_code ('B747346'))
print("2.", is_a_valid_code ( 'N 444
print("3.", is_a_valid_code('T 400 4854'))
print("4.", is_a_valid_code('S 444S454'))
print("5.", is_a_valid_code('P '))
print("6.", is_a_valid_code('T
1. True
454')) 2. True
3. False
4. False
5. False
'))
6. True
Transcribed Image Text:Define 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: code_letters min_for_each_letter max_for_each_letter ["S", "B", "N", "T", "P"] %3D [1, 3, 4, 0, 3] #inclusive [7, 9, 6, 7, 5] #inclusive %3D where: code_letters is the list of code letters which are valid for the first letter of the code string, min_for_each_letter is a list which contains the minimum possible number (inclusive) for each digit following that letter, max_for_each_letter is a list which contains the maximum possible number (inclusive) for each digit following that letter. For example, the third element of the code_letters list is the letter 'N', the corresponding third element of the min_for_each_letter list is 4 and the corresponding third element of the max_for_each_letter list is 6. This indicates that the code digits which follows the letter 'N' can be any number made up of the digits 4, 5 or 6. The number part of a valid code string can also contain any number of spaces. Note: The number part of a parameter code string to be tested could contain an alphabetic character thus making the code not valid. You will find it useful to use the string method, isdigit(), which returns True if a string is a digit, False otherwise. Some examples of the function being called are shown below. For example: Test Result print("1.", is_a_valid_code ('B747346')) print("2.", is_a_valid_code ( 'N 444 print("3.", is_a_valid_code('T 400 4854')) print("4.", is_a_valid_code('S 444S454')) print("5.", is_a_valid_code('P ')) print("6.", is_a_valid_code('T 1. True 454')) 2. True 3. False 4. False 5. False ')) 6. True
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.
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.
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 0
[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_dice_score() 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:
Test
Result
print("1:", get_dice_score([5, 3, 2, 5, 4, 5, 6, 4, 3]))
print("2:", get_dice_score( [3, 4, 1, 5, 3, 1, 4, 61))
print("3:", get_dice_score( [5, 3, 2, 2, 6, 4, 5, 1, 41))
1: 0
2: 2
3: 21
4: 19
print("4:", get_dice_score([2, 1, 1, 1, 2, 3, 3, 1, 3, 2]))
print("5:", get_dice_score( [3, 4, 1, 5, 2, 1, 5, 1, 2, 3, 4, 6])) 5: 37
print("6:", get_dice_score([]))
6: 0
Transcribed Image Text: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. 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. 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 0 [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_dice_score() 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: Test Result print("1:", get_dice_score([5, 3, 2, 5, 4, 5, 6, 4, 3])) print("2:", get_dice_score( [3, 4, 1, 5, 3, 1, 4, 61)) print("3:", get_dice_score( [5, 3, 2, 2, 6, 4, 5, 1, 41)) 1: 0 2: 2 3: 21 4: 19 print("4:", get_dice_score([2, 1, 1, 1, 2, 3, 3, 1, 3, 2])) print("5:", get_dice_score( [3, 4, 1, 5, 2, 1, 5, 1, 2, 3, 4, 6])) 5: 37 print("6:", get_dice_score([])) 6: 0
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education