Case study of tuples and Case Study of tuples
Case 1: Enter a number and convert it to a Chinese number. For example: 1234567890-> yanyao
Method01:
Number = input ("Enter a number:")
ForIInRange (len (number )):
If"0"InNumber [I]:
Print ("Zero", End ="")
If"1"InNumber [I]:
Print ("Yi", End ="")
If"2"InNumber [I]:
Print ("II.", End ="")
If"3"InNumber [I]:
Print ("Parameter", End ="")
If"4"InNumber [I]:
Print ("Si", End ="")
If"5"InNumber [I]:
Print ("Wu", End ="")
If"6"InNumber [I]:
Print ("Lu", End ="")
If"7"InNumber [I]:
Print ("Bytes", End ="")
If"8"InNumber [I]:
Print ("Bytes", End ="")
If"9"InNumber [I]:
Print ("Bytes", End ="")
If"."InNumber [I]:
Print ("Point", End ="")
Method02: Use tuples
Chinese_number = ("Zero","Yi","II.","Parameter","Si","Wu","Lu","Bytes","Bytes","Bytes")
Number = input ("Enter a number:")
ForIInRange (len (number )):
If"."InNumber [I]:
Print ("Point", End ="")
Else:
Print (chinese_number [int (number [I])], end ="")
Execution result:
C: \ python \ python.exe C:/python/demo/file3.py
Enter a number: 123.45
Yiwu.com
Process finished with exit code 0
Case02:Generates a playing card based on the color and number
Poker_type = ("","","","")
Poker_number = ("3","4","5","6","7","8","9","10","J","Q","K","","2")
Poker_list = []
ForIInPoker_number:
ForJInPoker_type:
Poker_list.append (j + I)
Print (len (poker_list ))
Print (poker_list)
Execution result:
C: \ python \ python.exe C:/python/demo/file3.py
52
['3', '3', '3', '3', '4', '4', '4', '4', '5 ', '5', '5', '5', '6', '6', '6', '6', '7', '7', '7', '7 ', '7', '8', '8', '8', '8', '9', '9', '9', '10 ', '10', '10', '10', 'J', 'Q ', 'Q', 'k', 'A', '2 ', '2', '2']
Process finished with exit code 0