Home > database >  Python operation problem, can help you to write code in more detail
Python operation problem, can help you to write code in more detail

Time:04-27

3, input a string of a string, whether it is palindrome, such as Madam, Madam I 'is a palindrome,
Tip: to remove all the punctuation in a string of characters, and put all uppercase characters to lowercase characters to compare, such as "Madam, I" Madam ", after the transformation into "madamimadam", is read and the reverse is the same, for palindrome,
Import string # import string function library
String. Punctuation='!" #$%& \ '() *, +, -./:; <=> ? @ [\ \] ^ _ ` {|} ~
'String. Whitespace='\ t \ n \ x0b \ x0c \ r'
4. Write the game "mastermind," resource is a kind of code breaking game: there are eight different characters, randomly generated four to the machine, and arranged together, a guess game in the form of feedback, if the character right, wrong place, the prompt "=", if the position is right, the prompt "*", until "* * * *," says all you guessed it, give gamers 8 times opportunity, if not yet indicates failure,
Tip: import the random # import random function library
The random choice (s) # random from s to choose a character in the string
The problem solving steps:
Computer randomly generated a set of color sequence,
Set the user input color sequence, and carries on the comparison to random color,
Given an input number, more than often, fail, otherwise output "Bingo",
  • Related