# 1. Determine the True and False of the following logic statements. # 1),1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 # f t f t t # True # 2)(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False # f f f t # 2. Find the value of the following logic statement. # 1),8 or 3 and 4 or 2 and 0 or 9 and 7) # 8 # 2),0 or 2 and 3 and 4 or 6 and 0 or 3 # 3. What is the result of the following? # 1)、6 or 2 > 1 # 6 # 2)、3 or 2 > 1 # 3 # 3)、0 or 5 < 4 # False # print(3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2) # 4)、5 < 4 or 3 # 3 # 5)、2 > 1 or 6 # True # 6)、3 and 2 > 1 # True # 7)、0 and 3 > 1 # 0 # 8)、2 > 1 and 3 #3 # 9)、3 > 1 and 0 #0 # 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 # 2 # 4. Briefly describe variable naming conventions # Variables consist of numbers, letters, and underscores and cannot start with numbers # cannot be a python keyword # cannot be Chinese # Variables are descriptive # 5. name = input(”>>>”) What data type is the name variable? # string # 6. The basic structure of an if conditional statement? #if condition: # result # 7. Basic structure of while loop statement? # while condition: # result: # 8. Write code: Calculate the sum of all numbers except 88 in 1 - 2 + 3 ... + 99? # i=1 # sum=0 # while i <100: # if i ==88: # i = i + 1 # continue # # elif i% 2 == 0: # sum-=i # else: # sum+=i # i+=1 # print(sum) # 9. The user logs in (three chances to make mistakes) and displays the remaining number of mistakes each time they make a mistake (hint: use string formatting) # i = 1 # while i<4: # name = input('please enter your username') # key = input('please enter your password') # if name=='zhujun' and key=='abcdefg' : # print('SUCCEED') # break # else: # print('WRONG!You have %d of 3 chances'%(3-i)) # i +=1 # # i=1 # while i<4: # name = input('please enter your username') # psd= input('please enter your password') # if name=='zhujun'and psd=='123456': # print('succeed') # break # else: # print('wrong you still have %d chances'%(3-i)) # i+=1 # 10. Briefly describe the relationship between ascii, unicode, and utf-8 encoding? # Use ascii code at the beginning, there are a total of 256 possibilities, not enough, just create a universal code (uncoide) on the basis of ascii code, uncoide starts with 16 digits, but Chinese cannot be satisfied, upgrade to 32 digits, # But it is too resource-intensive, upgrade to utf-8 # # 11. Briefly describe the relationship between bits and bytes? # 8 bits a byte # 12. How many bytes does "old boy" use UTF-8 encoding? How many bytes does it take to use GBK encoding? #9,6 # 13. Requirements for making interesting template programs: wait for the user to input name, location, hobbies, according to the user's # Arbitrary reality for names and hobbies, such as: dear and lovable xxx, most like to be in xxx place # name=input('>>>Please enter your name') # location=input('>>>Please enter your location') # hobbie=input('>>>Please enter your hobbies') # msg='Dear %s, I like %s, in %s' %(name,hobbie,location) # print(msg) # # 14. Wait for user input, # Detect whether the user input contains sensitive characters? if it exists # Sensitive characters prompt "Please re-enter if there are sensitive characters", and allow the user to re-enter and print. sensitive # Sensitive characters: "little pink", "big hammer" # while 1: # a=input('>>>Please enter your comment') # if a.find('Little Pink')!=-1 or a.find('Big Hammer')!=-1: # print('There are sensitive characters, please re-enter') # continue # else: # print('input is correct') # break # while 1: # comment=input('Please enter your comment') # s1='Little pink tender' # s2='Big Hammer' # if s1 in comment: # print('Contains sensitive characters, please re-enter') # elif s2 in comment: # print('Contains sensitive characters, please re-enter') # else: # print('input is correct') # break # 15. Single-line and multi-line comments? # Single line comment: # # Multi-line comments: '' or ''' ''' or '' '' # 16. Briefly describe the difference between Python 3 and Python 2 that you know? # python2: There are bad habits in other languages, there is a lot of repeated code # python3: simple, clear, beautiful # Print function: python2 does not need parentheses, python3 must add parentheses # 17. Look at the code writing result: # a = 1>2 or 4<7 and 8 == 8 # print(a) # True
python exercise 1
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324967403&siteId=291194637
Recommended
Ranking