Question

# Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...

Implement the following functions in the given code:

Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different.

Use the function descriptions provided in the code to replace the pass keyword with the necessary code.

Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each function has. Do not change the parameters. Do not change the names of the parameters and do not change the values of the parameters. Just make use of the values given to you.

When you run your program it will load, execute, and finish. Nothing will display unless you write test code outside of the functions.

Read all of the comments in the starter very carefully. All the necessary requirements are written out for you.

Starter code:

#

# I am importing this module so we can use its functions. # import random # Reference: https://docs.python.org/3/library/random.html

# ---------------------------------------------------------

# ---------------------------------------------------------

#

# Poker cards are numbered 1 through 13 (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King)

# and come in four suits: Spades, Hearts, Clubs, Diamonds.

#

# random_suit_number() returns a number 0 <= N < 4. Section 4.5 of your textbook covers this.

#

# get_card_suit_string_from_number(n) takes an integer and returns a string with the name of a suit:

# 1 ---> 'Hearts'

# 2 ---> 'Clubs'

# 3 ---> 'Diamonds'

# Note that get_card_suit_string_from_number(n) should return None if n is not a valid value. def random_suit_number(): ''' Returns a random integer N such that 0 <= N < 4. ''' pass def get_card_suit_string_from_number(n): ''' Returns the name of the suit that corresponds to the value n, or None if n is an invalid number. ''' pass

# Expected results:

# get_card_suit_string_from_number(1) ----> 'Hearts'

# get_card_suit_string_from_number(5) ----> None

# get_card_suit_string_from_number(-1) ----> None

#

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# Poker cards are numbered 1 through 13 (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King)

# and come in four suits: Spades, Hearts, Clubs, Diamonds.

#

# random_value_number() returns a number 1 <= N <= 13. Section 4.5 of your textbook covers this.

#

# get_card_value_string_from_number(n) takes an integer and returns a string with the name of a card value:

# 1 ---> 'Ace' # 2 ---> '2' # 3 ---> '3' # ... # 10 ---> '10' # 11 ---> 'Jack' # 12 ---> 'Queen' # 13 ---> 'King'

# Note that get_card_value_string_from_number(n) should return None if n is not a valid value. def random_value_number(): pass def get_card_value_string_from_number(n): pass

# Expected results: # get_card_value_string_from_number(12) ---> 'Queen'

# get_card_value_string_from_number(7) ---> '7'

# get_card_value_string_from_number(-7) ---> None

# get_card_value_string_from_number(0) ---> None

# get_card_value_string_from_number(14) ---> None

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

#

# The rules for determining whether a year is a leap year (it has # February 29 on the calendar) are a little strange:

# - a year is a leap year if it is a multiple of 4

# - unless it is a multiple of 100, in which case it is NOT a leap year

# - unless it is a multiple of 400, in which case it IS a leap year def is_leap_year(year): ''' Return True if year is a leap year, or False otherwise. ''' pass

#

# Expected results:

# is_leap_year(2000) ----> True

# is_leap_year(2001) ----> False

# is_leap_year(2012) ----> True

# is_leap_year(2040) ----> True

# is_leap_year(2100) ----> False

# is_leap_year(2104) ----> True

# is_leap_year(2200) ----> False

# is_leap_year(2400) ----> True

# is_leap_year(3000) ----> False

#

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

#

# Convert a numerical grade to a letter grade using the following chart:

# A 90 and higher

# B 80 to 89

# C 70 t0 79

# D 60 to 69

# F 0 to 59 def get_letter_grade_version_1(x): ''' Return the letter grade corresponding to the given numerical grade. '''

# Assume all inputs are valid and do not do any extra work. pass

# Expected results:

# get_letter_grade_version_1('70') ----> should cause an error

# get_letter_grade_version_1('AB') ----> should cause an error

#

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

#

# Same grade chart as above, but check whether x is an integer.

# If x is not an integer then return None. def get_letter_grade_version_2(x): ''' Return the letter grade corresponding to the given numerical grade, or None if x is not an integer. ''' pass

# Expected results: # get_letter_grade_version_2(85) ----> 'B'

# # ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

# ---------------------------------------------------------

#

# Same grade chart as above, but do what you can to interpret

# x as a number and to round to the nearest whole number.

# Return None if you cannot interpret x as a number. def get_letter_grade_version_3(x): ''' Return the letter grade corresponding to the given numerical grade, given the instructions. ''' pass

# Expected results:

# # ---------------------------------------------------------

# ---------------------------------------------------------

Here is the Python code:

``````import random

def random_suit_number ():
return random.randint (0, 3)

def get_card_suit_string_from_number(n):
if n == 0:  return ('Spades')
if n == 1:  return ('Hearts')
if n == 2:  return ('Clubs')
if n == 3:  return ('Diamonds')
return ('None')

def random_value_number():
return random.randint (1, 13)

def get_card_value_string_from_number(n):
if n == 1: return 'Ace'
if n == 11: return 'Jack'
if n == 12: return 'Queen'
if n == 13: return 'King'
if n >= 2 and n <= 10: return str(n)
return ('None')

def is_leap_year(year):
if year % 400 == 0: return True
if year % 100 == 0: return False
if year % 4 == 0: return True
return False

if x >= 90: return 'A'
if x >= 80: return 'B'
if x >= 70: return 'C'
if x >= 60: return 'D'
return 'F'

if not isinstance (x, int) and not isinstance (x, float) : return 'None'

try:
x = float(x)
except ValueError:
return 'None'
``````

#### Earn Coins

Coins can be redeemed for fabulous gifts.

##### Need Online Homework Help?

Most questions answered within 1 hours.

##### Active Questions
• Write 5 paragraphs, 5 sentences each to compare and contrast the two project management tools used...
• Consider the economy of Wiknam. The consumption function is given by C = 250 + 0.6...
• MS KP MM Corporation is a manufacturer that produces cosmetics. The following information has been taken...
• Dr. Bunson Honeydew and Dr. Strangepork both wanted to know how effective TV ads were at...
• 1)  Consider the following temperature surroundings. Ground level, 21oC; 500m, 20oC; 600m, 19oC; 1000m, 20oC. If we...
• 1. An AA iron-nickel battery delivers a constant current of 750 mA at 1.2 V (a)Calculate...