current position:Home>British one-to-one student Python poker homework Q & A

British one-to-one student Python poker homework Q & A

2022-02-02 07:42:58 AndersonHjb

Hello , I'm yuechuang .

The article first :www.aiyc.top/2094.html

 Insert picture description here

 Insert picture description here

Code :www.aiycoj.cn/?id=bc5e0e0…

Job content

Write a program , Accept user input , Describe a playing card ( Use the following shorthand symbols Short-hand), And print out Description.  Insert picture description here

requirement

  • User input can only be 2 perhaps 3 Characters , No spaces . for example 10H,3D.
  • First character ( Or the first two characters , If the card is 10) To be in Ranks in , The last character should be in Suits in .
  • Whether the user enters upper or lower case letters , The program should run smoothly
  • If the user enters substandard characters or the characters do not exist, it is the same as Ranks and Suits, It should be reported Invalid Card Entered.

Input & Output Example

 Insert picture description here The code she wrote was right , So I just put the code she wrote :

shorthand = input("Enter the card notation: ").upper()
length = len(shorthand)
ranks = {'1': 'One', '2': 'Two', '3': 'Three', '4': 'Four', '5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight', '9': 'Nine', 'A': 'Ace', 'J': 'Jack', 'Q': 'Queens', 'K': 'King'}
suits = {'H': 'Hearts', 'D': 'Diamond', 'S': 'Spades', 'C': 'Clubs'}

if length == 3:
    if shorthand[0:2] == '10' and shorthand[-1] in suits:
        print('Ten of ' + suits[shorthand[-1]])

    else:
        print('Invalid Card Entered')

elif length == 2:

    if shorthand[0] in ranks and shorthand[-1] in suits:
        print(ranks[shorthand[0]] + ' of ' + suits[shorthand[-1]])

    else:
        print('Invalid Card Entered')

else:
    print('Invalid Card Entered')
 Copy code 

 Insert picture description here

good , That's it . Class is over !

AI Yuechuang ·V:Jiabcdefh

copyright notice
author[AndersonHjb],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202020742569807.html

Random recommended