Exercise 1:
Exercise 2: designing a user management system
users=['root','westos','bob'] passwds=['123','456','789'] for i in range(3): user=raw_input('Please enter the user name:') if user in users: ##If the user exists inpasswd=raw_input('Please input a password:') ##User exists to input password index =users.index(user) passwd=passwds[index] if passwd == inpasswd: print 'Landing successfully' break else: print 'Incorrect password,You still have%d Second chance'%(2-i) else: print 'user does not exist,You still have%d Second chance'%(2-i) else: print'Three opportunities to use up,Please wait'
Exercise 3: user management system 2.0
print"Administrator login".center(50,"*") users=['root','westos','bob'] passwds=['123','456','789'] inuser=raw_input("Administrator user:") inpasswd=raw_input("Administrator password:") if inuser =='admin'and inpasswd =='admin': print 'Administrator login succeeded' print 'User information management'.center(50,'*') while True: print """ 1- Add user information 2- Delete user information 3- View user information 4- Sign out """ chioce=raw_input("Please enter your choice:") if chioce == '1': print 'Add user information'.center(50,'*') addUser=raw_input('Add user:') if addUser in users: print'user%s Already exist'%addUser else: addPasswd = raw_input("Password:") users.append(addUser) passwds.append(addPasswd) print 'Add user%s Success'%addUser elif chioce=='2': print 'Delete user information'.center(50, '*') delUser=raw_input('Users to delete:') if delUser in users: index=users.index(delUser) users.remove(delUser) passwds.pop(index) print 'User deleted successfully' else: print '%s user does not exist'%delUser elif chioce == '3': print 'View user information'.center(50,'*') print '\t User name\t Password' usercount=len(users) for i in range(usercount): print '\t%s\t%s'%(users[i],passwds[i]) elif chioce == '4': exit() else: 'Please enter the correct choice' else: "Administrator login failed"
Exercise 4: Huawei machine test questions:
Obviously, I want to invite some students to do a questionnaire survey together in school, in order to make the experiment objective
He first generated N random integers (n < = 1000) between 1 and 1000 by computer. N is input by the user. For
Only one of the repeated numbers should be kept, and the rest of the same numbers should be removed. Different numbers correspond to different student numbers, and then these numbers should be removed
Sort the numbers from small to large. Go to the students in the order arranged for investigation. Please help Mingming complete the "de duplication" and sorting work
# import random # li=[] # N = int (raw'input ('Please enter an integer: ') # for i in range(n): # num=random.randint(1,1000) # li.append(str(num)) # print sorted(list(set(li))) import random s=set([]) for i in range(int(raw_input('N: '))): s.add(random.randint(1,1000)) print s print sorted(s)
Exercise 5: repeat statistics
Randomly generate 1000 integers in the range of [20100], and output all different numbers and the number of repetitions of each number in ascending order
for i in range(1000): num=random.randint(20,100) list.append(num) list1=sorted(list) for j in list1: if j in dict: dict[j]+=1 else: dict[j]=1 print dict
Exercise 6: repeated words: it is thought that spaces are used as separators between words
The user enters an English sentence and prints out each word and the number of times it is repeated
str=raw_input('Enter an English sentence:') dict={} str1=str.split(' ') for i in str1: if i in dict: dict[i]+=1 else: dict[i]=1 print dict