Python 小型项目大全 31~35
三十一、猜数字
原文:http://inventwithpython.com/bigbookpython/project31.html
猜数字是初学者练习基本编程技术的经典游戏。在这个游戏中,电脑会想到一个介于 1 到 100 之间的随机数。玩家有 10 次机会猜出数字。每次猜中后,电脑会告诉玩家它是太高还是太低。
运行示例
当您运行guess.py
时,输出将如下所示:
Guess the Number, by Al Sweigart email@protectedI am thinking of a number between 1 and 100.
You have 10 guesses left. Take a guess.
> 50
Your guess is too high.
You have 9 guesses left. Take a guess.
> 25
Your guess is too low.
`--snip--`
You have 5 guesses left. Take a guess.
> 42
Yay! You guessed my number!
工作原理
猜数字使用了几个基本的编程概念:循环、if-else
语句、函数、方法调用和随机数。Python 的random
模块生成伪随机数——看似随机但技术上可预测的数字。对于计算机来说,伪随机数比真正的随机数更容易生成,对于视频游戏和一些科学模拟等应用来说,伪随机数被认为是“足够随机”的。
Python 的random
模块从一个种子值产生伪随机数,从同一个种子产生的每个伪随机数流都将是相同的。例如,在交互式 shell 中输入以下内容:
>>> import random
>>> random.seed(42)
>>> random.randint(1, 10); random.randint(1, 10); random.randint(1, 10)
2
1
5
如果您重新启动交互式 shell 并再次运行这段代码,它会产生相同的伪随机数:2
、1
、5
。视频游戏《我的世界》(也叫《挖矿争霸》)从起始种子值生成其伪随机虚拟世界,这就是为什么不同的玩家可以通过使用相同的种子来重新创建相同的世界。
"""Guess the Number, by Al Sweigart email@protected
Try to guess the secret number based on hints.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: tiny, beginner, game"""import randomdef askForGuess():while True:guess = input('> ') # Enter the guess.if guess.isdecimal():return int(guess) # Convert string guess to an integer.print('Please enter a number between 1 and 100.')print('Guess the Number, by Al Sweigart email@protected')
print()
secretNumber = random.randint(1, 100) # Select a random number.
print('I am thinking of a number between 1 and 100.')for i in range(10): # Give the player 10 guesses.print('You have {} guesses left. Take a guess.'.format(10 - i))guess = askForGuess()if guess == secretNumber:break # Break out of the for loop if the guess is correct.# Offer a hint:if guess < secretNumber:print('Your guess is too low.')if guess > secretNumber:print('Your guess is too high.')# Reveal the results:
if guess == secretNumber:print('Yay! You guessed my number!')
else:print('Game over. The number I was thinking of was', secretNumber)
在输入源代码并运行几次之后,尝试对其进行实验性的修改。你也可以自己想办法做到以下几点:
- 创建一个“猜字母”变体,根据玩家猜测的字母顺序给出提示。
- 根据玩家之前的猜测,在每次猜测后提示说“更热”或“更冷”。
探索程序
试着找出下列问题的答案。尝试对代码进行一些修改,然后重新运行程序,看看这些修改有什么影响。
- 如果把第 11 行的
input('> ')
改成input(secretNumber)
会怎么样? - 如果将第 14 行的
return int(guess)
改为return guess
,会得到什么错误信息? - 如果把第 20 行的
random.randint(1, 100)
改成random.randint(1, 1)
会怎么样? - 如果把第 24 行的
format(10 - i)
改成format(i)
会怎么样? - 如果将第 37 行的
guess == secretNumber
改为guess = secretNumber
,会得到什么错误信息?
三十二、容易受骗的人
原文:http://inventwithpython.com/bigbookpython/project32.html
在这个简短的节目中,你可以学到让一个容易受骗的人忙碌几个小时的秘密和微妙的艺术。我不会破坏这里的妙语。复制代码并自己运行。这个项目对初学者来说很棒,不管你是聪明的还是。。。不太聪明。
运行示例
当您运行gullible.py
时,输出将如下所示:
Gullible, by Al Sweigart email@protected
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> yes
Do you want to know how to keep a gullible person busy for hours? Y/N
> YES
Do you want to know how to keep a gullible person busy for hours? Y/N
> TELL ME HOW TO KEEP A GULLIBLE PERSON BUSY FOR HOURS
"TELL ME HOW TO KEEP A GULLIBLE PERSON BUSY FOR HOURS" is not a valid yes/no response.
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> n
Thank you. Have a nice day!
工作原理
为了更加用户友好,你的程序应该尝试解释用户可能的输入。例如,这个程序问用户一个是/否的问题,但是对于玩家来说,简单地输入y
或n
而不是输入完整的单词会更简单。如果玩家的CapsLock
键被激活,程序也可以理解玩家的意图,因为它会在玩家输入的字符串上调用lower()
字符串方法。这样,'y'
、'yes'
、'Y'
、'Yes'
、'YES'
都被程序解释的一样。玩家的负面反应也是如此。
"""Gullible, by Al Sweigart email@protected
How to keep a gullible person busy for hours. (This is a joke program.)
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: tiny, beginner, humor"""print('Gullible, by Al Sweigart email@protected')while True: # Main program loop.print('Do you want to know how to keep a gullible person busy for hours? Y/N')response = input('> ') # Get the user's response.if response.lower() == 'no' or response.lower() == 'n':break # If "no", break out of this loop.if response.lower() == 'yes' or response.lower() == 'y':continue # If "yes", continue to the start of this loop.print('"{}" is not a valid yes/no response.'.format(response))print('Thank you. Have a nice day!')
探索程序
试着找出下列问题的答案。尝试对代码进行一些修改,然后重新运行程序,看看这些修改有什么影响。
- 如果把第 11 行的
response.lower() == 'no'
改成response.lower() != 'no'
会怎么样? - 如果把第 8 行的
while True:
改成while False:
会怎么样?
三十三、黑客小游戏
原文:http://inventwithpython.com/bigbookpython/project33.html
在这个游戏中,玩家必须通过猜测一个七个字母的单词作为秘密密码来入侵电脑。电脑的记忆库显示可能的单词,并提示玩家每次猜测的接近程度。例如,如果密码是MONITOR
,但玩家猜了CONTAIN
,他们会得到提示,七个字母中有两个是正确的,因为MONITOR
和CONTAIN
的第二个和第三个字母都是字母O
和N
。这个游戏类似于项目 1,“百吉饼”,以及辐射系列视频游戏中的黑客迷你游戏。
运行示例
当您运行hacking.py
时,输出将如下所示:
Hacking Minigame, by Al Sweigart email@protected
Find the password in the computer's memory:
0x1150 $],>@|~~RESOLVE^ 0x1250 {>+)<!?CHICKEN,%
0x1160 }@%_-:;/$^(|<|!( 0x1260 .][})?#@#ADDRESS
0x1170 _;)][#?<&~$~+&}} 0x1270 ,#=)>{-;/DESPITE
0x1180 %[!]{email@protected?~, 0x1280 }/.}!-DISPLAY%%/
0x1190 _[^%[@}^<_+{email@protected$~ 0x1290 =>>,:*%email@protected+{%#.
0x11a0 )?~/)+PENALTY?-= 0x12a0 >[,?*#email@protected$/
`--snip--`
Enter password: (4 tries remaining)
> resolve
Access Denied (2/7 correct)
Enter password: (3 tries remaining)
> improve
A C C E S S G R A N T E D
工作原理
这个游戏有一个黑客主题,但不涉及任何实际的电脑黑客行为。如果我们只是在屏幕上列出可能的单词,游戏就会完全一样。然而,模仿计算机记忆库的装饰性添加传达了一种令人兴奋的计算机黑客的感觉。对细节和用户体验的关注将一个平淡、无聊的游戏变成了一个令人兴奋的游戏。
"""Hacking Minigame, by Al Sweigart email@protected
The hacking mini-game from "Fallout 3". Find out which seven-letter
word is the password by using clues each guess gives you.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: large, artistic, game, puzzle"""# NOTE: This program requires the sevenletterwords.txt file. You can
# download it from https://inventwithpython.com/sevenletterwords.txtimport random, sys# Set up the constants:
# The garbage filler characters for the "computer memory" display.
GARBAGE_CHARS = 'email@protected#$%^&*()_+-={}[]|;:,.<>?/'# Load the WORDS list from a text file that has 7-letter words.
with open('sevenletterwords.txt') as wordListFile:WORDS = wordListFile.readlines()
for i in range(len(WORDS)):# Convert each word to uppercase and remove the trailing newline:WORDS[i] = WORDS[i].strip().upper()def main():"""Run a single game of Hacking."""print('''Hacking Minigame, by Al Sweigart email@protected
Find the password in the computer's memory. You are given clues after
each guess. For example, if the secret password is MONITOR but the
player guessed CONTAIN, they are given the hint that 2 out of 7 letters
were correct, because both MONITOR and CONTAIN have the letter O and N
as their 2nd and 3rd letter. You get four guesses.\n''')input('Press Enter to begin...')gameWords = getWords()# The "computer memory" is just cosmetic, but it looks cool:computerMemory = getComputerMemoryString(gameWords)secretPassword = random.choice(gameWords)print(computerMemory)# Start at 4 tries remaining, going down:for triesRemaining in range(4, 0, -1):playerMove = askForPlayerGuess(gameWords, triesRemaining)if playerMove == secretPassword:print('A C C E S S G R A N T E D')returnelse:numMatches = numMatchingLetters(secretPassword, playerMove)print('Access Denied ({}/7 correct)'.format(numMatches))print('Out of tries. Secret password was {}.'.format(secretPassword))def getWords():"""Return a list of 12 words that could possibly be the password.The secret password will be the first word in the list.To make the game fair, we try to ensure that there are words witha range of matching numbers of letters as the secret word."""secretPassword = random.choice(WORDS)words = [secretPassword]# Find two more words; these have zero matching letters.# We use "< 3" because the secret password is already in words.while len(words) < 3:randomWord = getOneWordExcept(words)if numMatchingLetters(secretPassword, randomWord) == 0:words.append(randomWord)# Find two words that have 3 matching letters (but give up at 500# tries if not enough can be found).for i in range(500):if len(words) == 5:break # Found 5 words, so break out of the loop.randomWord = getOneWordExcept(words)if numMatchingLetters(secretPassword, randomWord) == 3:words.append(randomWord)# Find at least seven words that have at least one matching letter# (but give up at 500 tries if not enough can be found).for i in range(500):if len(words) == 12:break # Found 7 or more words, so break out of the loop.randomWord = getOneWordExcept(words)if numMatchingLetters(secretPassword, randomWord) != 0:words.append(randomWord)# Add any random words needed to get 12 words total.while len(words) < 12:randomWord = getOneWordExcept(words)words.append(randomWord)assert len(words) == 12return wordsdef getOneWordExcept(blocklist=None):"""Returns a random word from WORDS that isn't in blocklist."""if blocklist == None:blocklist = []while True:randomWord = random.choice(WORDS)if randomWord not in blocklist:return randomWorddef numMatchingLetters(word1, word2):"""Returns the number of matching letters in these two words."""matches = 0for i in range(len(word1)):if word1[i] == word2[i]:matches += 1return matchesdef getComputerMemoryString(words):"""Return a string representing the "computer memory"."""# Pick one line per word to contain a word. There are 16 lines, but# they are split into two halves.linesWithWords = random.sample(range(16 * 2), len(words))# The starting memory address (this is also cosmetic).memoryAddress = 16 * random.randint(0, 4000)# Create the "computer memory" string.computerMemory = [] # Will contain 16 strings, one for each line.nextWord = 0 # The index in words of the word to put into a line.for lineNum in range(16): # The "computer memory" has 16 lines.# Create a half line of garbage characters:leftHalf = ''rightHalf = ''for j in range(16): # Each half line has 16 characters.leftHalf += random.choice(GARBAGE_CHARS)rightHalf += random.choice(GARBAGE_CHARS)# Fill in the password from words:if lineNum in linesWithWords:# Find a random place in the half line to insert the word:insertionIndex = random.randint(0, 9)# Insert the word:leftHalf = (leftHalf[:insertionIndex] + words[nextWord]+ leftHalf[insertionIndex + 7:])nextWord += 1 # Update the word to put in the half line.if lineNum + 16 in linesWithWords:# Find a random place in the half line to insert the word:insertionIndex = random.randint(0, 9)# Insert the word:rightHalf = (rightHalf[:insertionIndex] + words[nextWord]+ rightHalf[insertionIndex + 7:])nextWord += 1 # Update the word to put in the half line.computerMemory.append('0x' + hex(memoryAddress)[2:].zfill(4)+ ' ' + leftHalf + ' '+ '0x' + hex(memoryAddress + (16*16))[2:].zfill(4)+ ' ' + rightHalf)memoryAddress += 16 # Jump from, say, 0xe680 to 0xe690.# Each string in the computerMemory list is joined into one large# string to return:return '\n'.join(computerMemory)def askForPlayerGuess(words, tries):"""Let the player enter a password guess."""while True:print('Enter password: ({} tries remaining)'.format(tries))guess = input('> ').upper()if guess in words:return guessprint('That is not one of the possible passwords listed above.')print('Try entering "{}" or "{}".'.format(words[0], words[1]))# If this program was run (instead of imported), run the game:
if __name__ == '__main__':try:main()except KeyboardInterrupt:sys.exit() # When Ctrl-C is pressed, end the program.
在输入源代码并运行几次之后,尝试对其进行实验性的修改。你也可以自己想办法做到以下几点:
- 在互联网上找到一个单词列表,创建你自己的文件
sevenletterwords.txt
,也许是一个由六个或八个字母组成的文件。 - 创建一个不同的“计算机内存”的可视化
探索程序
试着找出下列问题的答案。尝试对代码进行一些修改,然后重新运行程序,看看这些修改有什么影响。
- 如果把 133 行的
for j in range(16):
改成for j in range(0):
会怎么样? - 如果把第 14 行的
GARBAGE_CHARS = 'email@protected#$%^&*()_+-={}[]|;:,.<>?/'
改成GARBAGE_CHARS = '.'
会怎么样? - 如果把第 34 行的
gameWords = getWords()
改成gameWords = ['MALKOVICH'] * 20
会怎么样? - 如果将第 94 行的
return words
改为return
,会得到什么错误信息? - 如果把 103 行的
randomWord = random.choice(WORDS)
改成secretPassword = 'PASSWORD'
会怎么样?
三十四、刽子手和断头台
原文:http://inventwithpython.com/bigbookpython/project34.html
这个经典的文字游戏让玩家猜一个秘密单词的字母。对于每一个不正确的字母,刽子手的另一部分被画出来。在刽子手完成之前,试着猜出完整的单词。这个版本的密语都是兔子鸽子之类的动物,但是你可以用自己的一套话来代替这些。
HANGMAN_PICS
变量包含刽子手绞索每一步的 ASCII 艺术画字符串:
+--+ +--+ +--+ +--+ +--+ +--+ +--+| | | | | | | | | | | | | || O | O | O | O | O | O || | | | /| | /|\ | /|\ | /|\ || | | | | / | / \ || | | | | | |
===== ===== ===== ===== ===== ===== =====
对于游戏中的法式转折,您可以用以下描述断头台的字符串替换HANGMAN_PICS
变量中的字符串:
| | | |===| |===| |===| |===| |===|
| | | | | | | | | || /| || /|
| | | | | | | | | ||/ | ||/ |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | |/-\| |/-\| |/-\|
| | | | | |\ /| |\ /| |\ /| |\O/|
|=== |===| |===| |===| |===| |===| |===|
运行示例
当您运行hangman.py
时,输出将如下所示:
Hangman, by Al Sweigart email@protected+--+| |||||
=====
The category is: AnimalsMissed letters: No missed letters yet._ _ _ _ _
Guess a letter.
> e
`--snip--`+--+| |O |
/| |||
=====
The category is: AnimalsMissed letters: A I S
O T T E _
Guess a letter.
> r
Yes! The secret word is: OTTER
You have won!
工作原理
刽子手和断头台共享相同的游戏机制,但有不同的表现形式。这使得用 ASCII 艺术画的断头台图形替换 ASCII 艺术画的绞索图形变得容易,而不必改变程序遵循的主要逻辑。程序的表示和逻辑部分的分离使得用新的特性或不同的设计进行更新变得更加容易。在专业软件开发中,这种策略是软件设计模式或软件架构的一个例子,它关注于如何构建你的程序,以便于理解和修改。这主要在大型软件应用中有用,但是您也可以将这些原则应用到较小的项目中。
"""Hangman, by Al Sweigart email@protected
Guess the letters to a secret word before the hangman is drawn.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: large, game, word, puzzle"""# A version of this game is featured in the book "Invent Your Own
# Computer Games with Python" https://nostarch.com/inventwithpythonimport random, sys# Set up the constants:
# (!) Try adding or changing the strings in HANGMAN_PICS to make a
# guillotine instead of a gallows.
HANGMAN_PICS = [r"""
+--+
| |||||
=====""",
r"""
+--+
| |
O ||||
=====""",
r"""
+--+
| |
O |
| |||
=====""",
r"""
+--+
| |
O |
/| |||
=====""",
r"""
+--+
| |
O |
/|\ |||
=====""",
r"""
+--+
| |
O |
/|\ |
/ ||
=====""",
r"""
+--+
| |
O |
/|\ |
/ \ ||
====="""]# (!) Try replacing CATEGORY and WORDS with new strings.
CATEGORY = 'Animals'
WORDS = 'ANT BABOON BADGER BAT BEAR BEAVER CAMEL CAT CLAM COBRA COUGAR COYOTE CROW DEER DOG DONKEY DUCK EAGLE FERRET FOX FROG GOAT GOOSE HAWK LION LIZARD LLAMA MOLE MONKEY MOOSE MOUSE MULE NEWT OTTER OWL PANDA PARROT PIGEON PYTHON RABBIT RAM RAT RAVEN RHINO SALMON SEAL SHARK SHEEP SKUNK SLOTH SNAKE SPIDER STORK SWAN TIGER TOAD TROUT TURKEY TURTLE WEASEL WHALE WOLF WOMBAT ZEBRA'.split()def main():print('Hangman, by Al Sweigart email@protected')# Setup variables for a new game:missedLetters = [] # List of incorrect letter guesses.correctLetters = [] # List of correct letter guesses.secretWord = random.choice(WORDS) # The word the player must guess.while True: # Main game loop.drawHangman(missedLetters, correctLetters, secretWord)# Let the player enter their letter guess:guess = getPlayerGuess(missedLetters + correctLetters)if guess in secretWord:# Add the correct guess to correctLetters:correctLetters.append(guess)# Check if the player has won:foundAllLetters = True # Start off assuming they've won.for secretWordLetter in secretWord:if secretWordLetter not in correctLetters:# There's a letter in the secret word that isn't# yet in correctLetters, so the player hasn't won:foundAllLetters = Falsebreakif foundAllLetters:print('Yes! The secret word is:', secretWord)print('You have won!')break # Break out of the main game loop.else:# The player has guessed incorrectly:missedLetters.append(guess)# Check if player has guessed too many times and lost. (The# "- 1" is because we don't count the empty gallows in# HANGMAN_PICS.)if len(missedLetters) == len(HANGMAN_PICS) - 1:drawHangman(missedLetters, correctLetters, secretWord)print('You have run out of guesses!')print('The word was "{}"'.format(secretWord))breakdef drawHangman(missedLetters, correctLetters, secretWord):"""Draw the current state of the hangman, along with the missed andcorrectly-guessed letters of the secret word."""print(HANGMAN_PICS[len(missedLetters)])print('The category is:', CATEGORY)print()# Show the incorrectly guessed letters:print('Missed letters: ', end='')for letter in missedLetters:print(letter, end=' ')if len(missedLetters) == 0:print('No missed letters yet.')print()# Display the blanks for the secret word (one blank per letter):blanks = ['_'] * len(secretWord)# Replace blanks with correctly guessed letters:for i in range(len(secretWord)):if secretWord[i] in correctLetters:blanks[i] = secretWord[i]# Show the secret word with spaces in between each letter:print(' '.join(blanks))def getPlayerGuess(alreadyGuessed):"""Returns the letter the player entered. This function makes surethe player entered a single letter they haven't guessed before."""while True: # Keep asking until the player enters a valid letter.print('Guess a letter.')guess = input('> ').upper()if len(guess) != 1:print('Please enter a single letter.')elif guess in alreadyGuessed:print('You have already guessed that letter. Choose again.')elif not guess.isalpha():print('Please enter a LETTER.')else:return guess# If this program was run (instead of imported), run the game:
if __name__ == '__main__':try:main()except KeyboardInterrupt:sys.exit() # When Ctrl-C is pressed, end the program.
在输入源代码并运行几次之后,尝试对其进行实验性的修改。标有(!)
的注释对你可以做的小改变有建议。你也可以自己想办法做到以下几点:
- 添加一个“类别选择”功能,让玩家选择他们想玩的词的类别。
- 增加一个选择功能,这样玩家可以在游戏的刽子手和断头台版本之间进行选择。
探索程序
试着找出下列问题的答案。尝试对代码进行一些修改,然后重新运行程序,看看这些修改有什么影响。
- 如果删除或注释掉第 108 行的
missedLetters.append(guess)
会发生什么? - 如果把第 85 行的
drawHangman(missedLetters, correctLetters, secretWord)
改成drawHangman(correctLetters, missedLetters, secretWord)
会怎么样? - 如果把 136 行的
['_']
改成['*']
会怎么样? - 如果把 144 行的
print(' '.join(blanks))
改成print(secretWord)
会怎么样?
三十五、六边形网格
原文:http://inventwithpython.com/bigbookpython/project35.html
这个简短的程序产生一个类似于铁丝网的六角形网格的镶嵌图像。这说明你不需要很多代码就能做出有趣的东西。这个项目的一个稍微复杂一点的变体是项目 65,“闪光地毯”
注意,这个程序使用原始字符串,它在开始的引号前面加上小写的r
,这样字符串中的反斜杠就不会被解释为转义字符。
运行示例
图 35-1 显示了运行hexgrid.py
时的输出。
:显示六边形网格镶嵌图像的输出
工作原理
编程背后的力量在于它能让计算机快速无误地执行重复的指令。这就是十几行代码如何在屏幕上创建数百、数千或数百万个六边形。
在命令提示符或终端窗口中,您可以将程序的输出从屏幕重定向到文本文件。在 Windows 上,运行py hexgrid.py > hextiles.txt
创建一个包含六边形的文本文件。在 Linux 和 macOS 上,运行python3 hexgrid.py > hextiles.txt
。没有屏幕大小的限制,您可以增加X_REPEAT
和Y_REPEAT
常量并将内容保存到文件中。从那里,很容易将文件打印在纸上,用电子邮件发送,或发布到社交媒体上。这适用于你创作的任何计算机生成的作品。
"""Hex Grid, by Al Sweigart email@protected
Displays a simple tessellation of a hexagon grid.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: tiny, beginner, artistic"""# Set up the constants:
# (!) Try changing these values to other numbers:
X_REPEAT = 19 # How many times to tessellate horizontally.
Y_REPEAT = 12 # How many times to tessellate vertically.for y in range(Y_REPEAT):# Display the top half of the hexagon:for x in range(X_REPEAT):print(r'/ \_', end='')print()# Display the bottom half of the hexagon:for x in range(X_REPEAT):print(r'\_/ ', end='')print()
在输入源代码并运行几次之后,尝试对其进行实验性的修改。标有(!)
的注释对你可以做的小改变有建议。你也可以自己想办法做到以下几点:
- 创建更大尺寸的平铺六边形。
- 创建平铺的矩形砖块,而不是六边形。
为了练习,请尝试使用更大的六边形网格重新创建此程序,如下图所示:
/ \ / \ / \ / \ / \ / \ / \
/ \___/ \___/ \___/ \___/ \___/ \___/ \
\ / \ / \ / \ / \ / \ / \ /\___/ \___/ \___/ \___/ \___/ \___/ \___// \ / \ / \ / \ / \ / \ / \
/ \___/ \___/ \___/ \___/ \___/ \___/ \/ \ / \ / \ / \/ \ / \ / \ / \
/ \_____/ \_____/ \_____/ \_____
\ / \ / \ / \ /\ / \ / \ / \ /\_____/ \_____/ \_____/ \_____// \ / \ / \ / \/ \ / \ / \ / \
/ \_____/ \_____/ \_____/ \_____
探索程序
这是一个基础程序,所以没有太多的选项来定制它。取而代之的是,考虑你如何能类似地编程其他形状的模式。
相关文章:

Python 小型项目大全 31~35
三十一、猜数字 原文:http://inventwithpython.com/bigbookpython/project31.html 猜数字是初学者练习基本编程技术的经典游戏。在这个游戏中,电脑会想到一个介于 1 到 100 之间的随机数。玩家有 10 次机会猜出数字。每次猜中后,电脑会告诉玩…...

他又赚了一万美金
有一些学员真的挺能干的,收了一万刀,感到欣慰,毕竟在国外lead这条路,有很多人被骗,也有很多人赚钱。 但是大部分人跟着某一些所谓的大佬,最后自己却不动手操作。 从一开始怕跟我学习,到最后选…...
企业工程项目管理系统+spring cloud 系统管理+java 系统设置+二次开发
工程项目各模块及其功能点清单 一、系统管理 1、数据字典:实现对数据字典标签的增删改查操作 2、编码管理:实现对系统编码的增删改查操作 3、用户管理:管理和查看用户角色 4、菜单管理:实现对系统菜单的增删改查操…...

教你使用Apache搭建Http
Apache2默认采用的是80端口号,因此直接通过公网ip或域名就能访问。现实中,很多服务器本身就部署了许多其它服务,80端口号往往被占用,因此就需要将Apache2改成其它访问端口。 修改端口,首先需要修改/etc/apache2/ports…...

ZooKeeper+Kafka+ELK+Filebeat集群搭建实现大批量日志收集和展示
文章目录一、集群环境准备二、搭建 ZooKeeper 集群和配置三、搭建 Kafka 集群对接zk四、搭建 ES 集群和配置五、部署 Logstash 消费 Kafka数据写入至ES六、部署 Filebeat 收集日志七、安装 Kibana 展示日志信息一、集群环境准备 1.1 因为资源原因这里我就暂时先一台机器部署多…...

数据结构初阶 - 总结
-0- 数据结构前言 什么是数据结构 什么是算法 数据结构和算法的重要性-1- 时间复杂度和空间复杂度 👉数据结构 -1- 时间复杂度和空间复杂度 | C 算法效率 时间复杂度大O的渐进表示法eg 空间复杂度 常见复杂度对比OJ 消失的数组 轮转数组-2- 顺序表 与 链表 &am…...
代码随想录算法训练营第四十四天-动态规划6|518. 零钱兑换 II ,377. 组合总和 Ⅳ (遍历顺序决定是排列还是组合)
如果求组合数就是外层for循环遍历物品,内层for遍历背包。 如果求排列数就是外层for遍历背包,内层for循环遍历物品。 求物品可以重复使用时,最好是用一维数组,会比较方便。二维数组不想思考了,二维还是用在01背吧吧。…...

wma格式怎么转换mp3,4种方法超快学
其实我们在任何电子设备上所获取的音频文件都具有自己的格式,每种格式又对应着自己的属性特点。比如wma就是一种音质优于MP3的音频格式,虽然很多小伙伴比较青睐于wma所具有的音质效果,但也不得不去考虑因wma自身兼容性而引起很多播放器不能支…...

【数据结构与算法】判定给定的字符向量是否为回文算法
题目: Qestion: 试写一个算法判定给定的字符向量是否为回文。 回文解释: 回文是指正读反读均相同的字符序列,如“abba”和“abdba”均是回文,但“good”不是回文。 主要思路: 因为数据要求不是很严格并且是一个比较简单的…...

考研数二第十七讲 反常积分与反常积分之欧拉-泊松(Euler-Poisson)积分
反常积分 反常积分又叫广义积分,是对普通定积分的推广,指含有无穷上限/下限,或者被积函数含有瑕点的积分,前者称为无穷限广义积分,后者称为瑕积分(又称无界函数的反常积分)。 含有无穷上限/下…...

【论文总结】理解和减轻IoT消息协议的安全风险
理解和减轻IoT消息协议的安全风险介绍概述前置知识威胁模型MQTT IoT通信安全分析未授权的MQTT消息未授权的Will消息未经授权的保留消息MQTT会话管理故障未更新的会话订阅状态未更新的会话生命周期状态未经身份验证的 MQTT 身份客户端id劫持MQTT Topics的授权MQTT Topic不安全的…...
SpringBoot基础入门
一、概述 Spring Boot是一个开源的Java框架,它是基于Spring框架的基础之上创建的。Spring Boot可以帮助开发人员更快地创建Spring应用程序,并以最小的配置要求来运行它们。Spring Boot可以用于构建各种类型的应用程序,包括Web应用程序、RESTful API、批处理作业、消息传递应…...
jar 包与 war 包区别
1、war是一个web模块,其中需要包括WEB-INF,是可以直接运行的WEB模块;jar一般只是包括一些class文件,在声明了Main_class之后是可以用java命令运行的。 2、war包是做好一个web应用后,通常是网站,打成包部署…...

【数据结构:复杂度】时间复杂度
本节重点内容: 算法的复杂度时间复杂度的概念大O的渐进表示法常见时间复杂度计算举例⚡算法的复杂度 算法在编写成可执行程序后,运行时需要耗费时间资源和空间(内存)资源 。因此衡量一个算法的好坏,一般是从时间和空间两个维度来衡量的&…...

京东pop店铺订单导出
下载安装与运行 下载、安装与运行 语雀 特别提醒 只能导出已登录店铺的订单导出的收件人手机号是虚拟号 功能 主要是方便线下工厂发货的店主 所见即所得的导出自由选择导出项自由排序Excel导出列顺序导出过程中有进度提示,用户可以随时提前中止 什么是所见即所…...

论文阅读:Towards Stable Test-time Adaptation in Dynamic Wild World
今天阅读ICLR 2023 ——Towards Stable Test-time Adaptation in Dynamic Wild World Keywords:Test-time adaptation (TTA); 文章目录Towards Stable Test-time Adaptation in Dynamic Wild WorldProblem:motivation:Contributio…...
2022国赛27:Linux-1时间服务chrony配置
大赛试题内容: 3.利用chrony配置Linux-1为其他Linux主机提供时间同步服务。 解答过程: 安装chrony服务[root@cs1 ~]# yum -y install chrony 配置/etc/chrony.conf文件[root@cs1 ~]# vi /etc/chrony.conf 7行改为 server 10.10.70.101 iburst 23行改为 去掉#号 allow 1…...

Java——二维数组中的查找
题目链接 牛客在线oj题——二维数组中的查找 题目描述 在一个二维数组array中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二…...
Android 9.0 添加关机铃声功能实现
1.前言 在9.0的系统rom定制化开发中,在原生系统中,关于开机铃声和关机铃声是默认不支持的,系统默认支持开机动画和关机动画等功能,所以关于增加开机铃声和关机 铃声的相关功能,需要自己增加相关的关机铃声功能 2.添加关机铃声功能实现的核心类 frameworks\base\cmds\boo…...
IPv4 和 IPv6 的组成结构和对比
IPv4 和 IPv6 的组成结构和对比IPv4IPv6互联网协议 (IP) 是互联网通信的基础,IP 地址是互联网上每个设备的唯一标识符。目前最常用的 IP 协议是 IPv4,它已经有近 30 年的历史了。然而,IPv4 存在一些问题,例如: 地址空间不足:IPv4 …...

Pytorch安装后 如何快速查看经典的网络模型.py文件(例如Alexnet,VGG)(已解决)
当你用conda 安装好虚拟环境后, 找到你的Anaconda 的安装位置。 我的在D盘下; 然后 从Anaconda3文件夹开始:一级一级的查看,一直到models Anaconda3\envs\openmmlab\Lib\site-packages\torchvision\models 在models下面&#x…...

0x-1 记一次SGA PGA设置失败,重新开库
0、生产侧定时平台上传数据库11g hang,修改无法startup 厂商统一发放的虚拟机作为前置机导入平台后,直接开机使用。主机在虚拟化平台中,实例卡死后,按照虚拟机系统64G,原SGA2g,不知哪个大聪明给默认设置的。保守计划修…...
两轮自平衡机器人建模、LQR控制与仿真分析
以下是一个针对两轮自平衡机器人(平衡车) 的完整建模、控制设计与仿真分析报告,包含详细的理论推导、控制算法实现及Python仿真代码。 两轮自平衡机器人建模、LQR控制与仿真分析 1. 引言 两轮自平衡机器人是一种典型的欠驱动、非线性、不稳定系统,其动力学特性与倒立摆高度…...

Git GitHub Gitee
一、Git 是一个免费、开源的分布式版本控制系统。 版本控制:一种记录文件内容变化,以便将来查阅特定版本修订情况的系统。它最重要的就是可以记录文件修改历史记录,从而让用户可以看历史版本,方便版本切换。 1.和集中式版本控制…...
Python爬虫爬取天猫商品数据,详细教程【Python经典实战项目】
Python爬取天猫商品数据详细教程 一、前期准备 1. 环境配置 Python环境:确保已安装Python 3.x版本,建议使用Anaconda或直接从Python官网下载安装。第三方库: requests:用于发送HTTP请求。BeautifulSoup:用于解析HTM…...
[论文阅读] 软件工程 | 如何挖掘可解释性需求?三种方法的深度对比研究
如何挖掘可解释性需求?三种方法的深度对比研究 研究背景:当软件变复杂,我们需要“说明书” 想象你买了一台智能家电,却发现它的运行逻辑完全看不懂,按钮按下后毫无反应,故障时也不提示原因——这就是现代…...

平安养老险蚌埠中心支公司开展金融宣教活动
近日,平安养老保险股份有限公司(以下简称“平安养老险”)蚌埠中心支公司,走进某合作企业开展金融教育宣传活动。 活动现场,平安养老险蚌埠中心支公司工作人员通过发放宣传手册和小礼品等方式,向企业员工普…...

Redisson简明教程—你家的锁芯该换了
1.简介 各位攻城狮们,你还在使用原生命令来上锁么?看来你还是不够懒,饺子都给你包好了,你非要吃大饼配炒韭菜,快点改善一下“伙食”吧,写代码也要来点幸福感。今天咱们就来聊聊Redisson提供的各种锁&#…...
外网访问内网服务器常用的三种简单操作步骤方法,本地搭建网址轻松让公网连接
当本地内网环境搭建部署好服务器后,怎么设置让外网公网上连接访问到呢?或本身处于不同局域网间的主机,需要进行数据交互通信,又应该如何实现操作?这些都离不开外网对内网的访问配置。 总的来说外网访问内网服务器主要…...

【C语言预处理详解(下)】--#和##运算符,命名约定,命令行定义 ,#undef,条件编译,头文件的包含,嵌套文件包含,其他预处理指令
目录 五.#和##运算符 5.1--#运算符 5.2--##运算符 六.命名约定,#undef,命令行定义 6.1--命名约定 6.2--#undef 6.3--命名行定义 七.条件编译 常见的条件编译指令: 1.普通的条件编译: 2.多个分支的条件编译(可以利用条…...