If you want to "smooth" the game, you can start with a Python game and learn the practical application technology of the Python game. If you are interested in it, you can browse the following articles. I hope you will gain some benefits. The following is a detailed introduction to this article.
This is a sunny Saturday afternoon. You can browse the Internet leisurely. suddenly you see a small game on the message board. it is very simple, and the problem is: Put the five numbers 56789 into {[] [] [] * [] [] to maximize the result ..
You should first say to yourself: "What's the problem? Just put the largest number in the maximum number of digits. "Maybe it's wrong if you forget it. each result depends on the number of rows placed in other locations. you are interested in it. You are learning a fun programming language. Why not practice it?
As a result, you opened your beloved Python game and started to think: "In fact, what I want is a program. I gave it a combination of various numbers, and then it automatically helped me find the biggest one. if I input 111, 111, 1, 2, it will know that the calculation is * 11 and * 12, the larger result is 111*12, and the combination and product are output. this program is not difficult."
- 1 # calc.py
- 2 def calc(seq):
- 3 maximum = 0
- 4 max_item = []
- 5 for i in seq:
- 6 product = (i[0]*100 + i[1]*10 + i[2]) * (i[3]*10 + i[4])
- 7 if product > maximum:
- 8 maximum = product
- 9 max_item = i
- 10 elif product == maximum:
- 11 max_item += ','+i
- 12 return max_item, maximum
- 13
- 14 seq = [ [5,6,7,8,9], [5,6,7,9,8] ]
- 15 max_item, maximum = calc(seq)
- 16 print "Maximum at", max_item, ",product", maximum
You tried,
- $python calc.py
- Maximum at [5, 6, 7, 9, 8] ,product 90160
-
No problem. now you only need to give all the arrangement. after you have made a few attempts, I think it is too hard to use [100, 9], and I [0] * + I [1] * 10... the method seems too ugly, so you need to make a change. okay. Use a string. "56789", this input is more convenient, and int ("567") * int ("89") is much better, it should be faster. in addition, you can also shorten the program, which looks like written by experienced people. the above article introduces Python games.