# Python basic exercises

## 1. Number of printing 1-100

```for i in range(1, 101):
print(i)```

## 2. Print the sum of 1 + 2 +.. 100

```num = 1
sum = 0
while num < 101:
sum += num
num += 1
print(sum)```

## 3. Use while to output 1 2 3 4 6

```i = 1
while i < 7:
if i == 5:
print('')
else:
print(i)
i += 1```

## 4. Output all odd numbers in 1-100

```for i in range(1, 101):
if i % 2 != 0:
print(i)```

```username = 'liangxiao'
num = 1
while num < 4:
num += 1
break
else:
num = 4 - num
Num = 'You still have input times left%d' % (num)
print(Num)

## 6. Format output

```name = input('Please output your name: ')

information = '''
Your personal information is as follows:
''' % (name, age)

print(information)```

## 7. Basic operation of python

```6 or 2 > 1 =  6
3 or 2 > 1 =  3
0 or 5 < 4 =  False
5 < 4 or 3 = 3
2 > 1 or 6 = True
3 and 2 > 1 = True
0 and 3 > 1 = False
2 > 1 and 3 = 3
3 > 1 and 0 = 0
1 > 2 or 4 < 7 and 8 == 8
3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 = 2
not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 = False```

## 8. Calculation 1-2 + 3-4... + 99

```num = 0
sum = 0
while num < 100:
num += 1
if num == 88:
continue
elif num % 2 != 0:
sum += num
else:
sum -= num
print(sum)```

## 9. Set user input content detection

```input1 = input('Please output the password you need to register:')
sensitive_words = ['Flour hammer', 'Big hammer']
i = 0
while i < 3:
if input1 in sensitive_words:
else:
print('The output is correct and the login is successful!')
print('Welcome back!')
break
i += 1```

## 10. Simple verification of verification code

```code = 'AC8E'
code_input = input('Please output the verification code:')
if code_input.upper() == code:
print('Verifying and passing')
else:
print('Validation failed')```

## 11. Add a list user

```li = []
while True:
operation = input('Do you want to continue? ( Y/N)')
if operation.upper() == 'Y':
elif operation.upper() == 'N':
print('welcome to use this program!')
break
else:
else:
print('welcome to use this program!')
break```

## 12. List [11, 22... 99]; those greater than 66 are added to key2, and those less than 66 are added to key1

```list1 = [11, 22, 33, 44, 55, 66, 77, 88, 99]
dict1 = {'key1':'', 'key2':''}
list2 = []
list3 = []
for i in list1:
if i > 66:
list2.append(i)
else:
list3.append(i)
dict1['key2'] = list2
dict1['key1'] = list3
print(dict1)```

## 13. Output the list of commodities, input the serial number, and display the commodities selected by the user

#### Product list1 = ["mobile phone", "computer", "mouse pad", "yacht", the requirements are as follows:1: the page displays the serial number + commodity name, such as:1 mobile phone2 computer3 mouse pad4 yacht 2: enter the serial number of the selected product and print the product name 3: if the serial number of the product entered by the user is wrong, you will be prompted to enter it again. 4: the user enters Q or Q to exit the program. ""

```list1 = ['Mobile phone', 'Computer', 'Mouse pad', 'Yacht']
for i in list1:
print('{}\t{}'.format(list1.index(i)+1,i))
while 1:
if choose.isdigit():
if int(choose) > 0 and int(choose) < 5:
print('The input is correct!')
print(list1[int(choose)-1])
break
else:
print('The sequence you entered is wrong, please input again!')
continue
elif choose.isalpha():
if choose.upper() == 'Q':
print('good-bye!')
break
else:
print('Exit failed, your output is wrong')
continue
else:

## 14. Account registration and login verification

```while 1:
print('Can register√')
print('Registration succeeded!')
break
else:
input('The registration information is wrong, please re-enter\n')

for i in range(3):