1. Operators Expanding

Operator # 1 added: in / in Not 

'' 'is determined whether the indicated value generation Chinese string.
'China' is a value within the meaning of sequence generation string '' '
value =' I am Chinese "
v1 = 'China' in value

# Example 1:
'' '
Content = the INPUT (' Please enter content: ' )
IF 'refund' in content:
Print ( 'containing sensitive characters')
' ''


# example 2:
'' '
the while True:
content = iNPUT ( "Please enter content:')
IF 'refund' in content:
Print ( 'contains sensitive characters')
the else:
Print (Content)
BREAK
' ''

# 2. priority
'' '
not 2> 1 # error
not 2> 1 # correct
' ''


# 3.




'' '
The while True:
NUM = INPUT (' waiting for user input: ') # two cases and any one kind of the following output cycle to this step
value = int (num) # string into a digital
IF value> 66:
Print ( 'big')
elif value <66:
Print ( 'small')
the else:
Print ( 'right')
BREAK
'' '

# ②
' '' on the basis of a question, setting: the user three guesses,
if guessed within three, the speculation is displayed correctly, exit the loop;
If you do not guess right, you automatically exit the loop with 'fool' '' 'within three of the
# function to split
# features a user logs
' ''
username = input ( 'enter username:')
password = iNPUT ( 'enter password:') Note that the data structure type # output here for the character
if username == 'Zhang workers' and password ==' 123456 ':
Print (' guess the correct ')
The else:
Print ( 'guessing wrong')
'' '


# Function two, three chances
' ''
Requirements: allows the user to try up to three times, each attempt three times, if you have not guessed asked whether the user would like to continue playing, if the answer Y, it is allowed to continue to guess three times, this back and forth, if the answer N to exit into the program, if the guess right, you exit. '' ' # My way: ' ''
































1 = COUNT
the while COUNT <= 3:
Age = the INPUT ( 'Please enter ages:')
Age = int (Age)
IF Age == 23:
Print ( 'guessed')
BREAK
! elif Age = 23:
Print ( ' guessed wrong ') following the method of Comparative # redundancy here directly outputs' guessed wrong' can. Because the previous step if guessed it directly out of the loop.
COUNT ==. 3 IF:
Choice = INPUT ( 'whether to continue playing the Y / N:?')
IF Choice == 'the Y':
COUNT = 1 # Let the variable before returning while re = 1, then the previous steps
continue
Choice == IF 'N':
BREAK
the else:
Print ( 'mistyped')
BREAK
COUNT + =. 1
'' '

# otherwise: '
''


age = input ( 'Please enter ages:')
Age = int (Age)
IF Age == 23:
Print ( 'guessed')
BREAK
Print ( 'the wrong')
IF COUNT == 3:
Choice = the INPUT ( 'Do we still need to continue to play the Y / N:?')
iF Choice == 'the Y':
COUNT =. 1
continue
elif Choice == 'N':
BREAK
the else:
Print ( 'mistyped')
BREAK
COUNT + =. 1
' ''


# exercise to why the first two questions above if without else's
' ''
the while True:
NUM = the iNPUT ( 'enter a number:')
NUM = int (NUM)
if NUM == 3:
Print ( 'correct')
break
print ( 'error') # insert a circulation principle, this does not have to add the else
'' '


# ④ user login (unsuccessful attempts to enter the opportunity) and each remaining number of errors (Hint: Use string formatting) is displayed when transmission errors
# my approach :( incremental)
'' '
COUNT = 1
the while COUNT <= 3:
usr the iNPUT = (' Please enter your user name: ')
pwd = the iNPUT (' Please enter the password: ')
IF usr ==' Oldboy ' pwd == and 'alex':
Print ( 'Welcome!')
BREAK
Number The = 3 - COUNT
The warn = 'user name or password is incorrect, you still have chance% s'% (number,) # here got to re Create a variable
Print (The warn)
COUNT + =. 1
'' '

# otherwise: '
''
COUNT = 2
the while COUNT> = 0:
usr = iNPUT ( 'enter username:')
pwd = iNPUT ( 'Please input password:')
IF usr == 'Oldboy' and pwd == 'alex':
Print () 'Welcome!'
BREAK
The warn = 'user name or password is incorrect, you still have chance% s'% (count,) # here got to re-create a variable
Print (The warn)
COUNT - = 1
the else:
Print (' three chances have run out ')
' ''

Guess you like

Origin www.cnblogs.com/zyg-ayy/p/11070518.html
Recommended