3/9

Job (title will do):

1. The while loop output 1234568910

n = 1
while n < 11:
if n == 7:
n += 1
continue
else:
print(n)
n += 1

2. All numbers 1-100 and seek

sum = 0
n = 1
while n <= 100:
sum += n
n += 1
print(sum)

3. The outputs of all the odd-numbered 1-100

n = 1
while n <= 100:
if n % 2 == 1:
print(n)
n += 1
else:
n += 1

4. Output all even within 1-100

n = 1
while n <= 100:
if n % 2 != 1:
print(n)
n += 1
else:
n += 1

The request and all numbers 1-2 + 3-4 + 5 ... 99

sum1 = 0
sum2 = 0
n = 1
i = 1
while n <= 99:
if n % 2 == 1:
sum1 += n
n += 1
else:
n += 1
while i <= 99:
if i % 2 != 1:
sum2 += i
i += 1
else:
i += 1
print(sum1 - sum2)

6. User Login (three chances to retry)

= name '123'
pwd = '456'
n-0 =
the while n-<. 3:
USER_NAME = INPUT ( 'Enter ID:')
the user_pwd = INPUT ( 'Enter password:')
IF name and the user_pwd USER_NAME == == pwd :
Print ( 'Login successful')
BREAK
the else:
Print ( 'Login failed')
the n-1 + =
the else:
Print ( 'Login failed, please try again later.')

7: Guess the age of the game

要求:
允许用户最多尝试3次,3次都没猜对的话,就直接退出,如果猜对了,打印恭喜信息并退出

= Age '1111'
Chance = 0
the while Chance <. 3:
guess_age = INPUT ( 'Instantly guess:')
IF guess_age == Age:
Print ( 'regressed guessed')
BREAK
the else:
Print ( 'wrong Guess')
Chance +. 1 =

8: Guess the age of an upgraded version of the game (Optional Problem)

Requirements:
allows the user to try up to three times
per attempt three times, if you have not guessed, asked whether the user would like to continue playing, if the answer Y or y, then allowed to continue to guess three times, this back and forth, if the answer N or n, to exit the program
how guessed will exit
Age = '1111'
Yes = [ 'Y', 'the Y']
NO = [ 'n-', 'N']
Tag = True
Chance = 0
the while Tag:
guess_age = input ( 'Take a guess:')
IF guess_age == Age:
Print ( 'Congratulations, you guessed it')
Tag = False
the else:
Print ( 'the wrong')
Chance + 1 =
IF Chance == 3:
answer the iNPUT = ( 'Please continue to enter y / Y, exit enter the n-/ N:')
IF answer in yes:
Tag = True
Chance = 0
elif answer in NO:
( '! Welcome to the next use') Print
Tag False =
the else:
Print ( 'end program input error!')
Tag = False

Guess you like

Origin www.cnblogs.com/bailongcaptain/p/12450576.html
3/9