Day1-variable, loop, character encoding, day1-variable character encoding
1. You must introduce python.
Python is an interpreted, object-oriented, and dynamic data type high-level programming language.
Python was invented by Guido van rosum at the end of 1989. The first public release was released in 1991.
2. Enter the topic (isn't it too fast !?), If-elif-else judgment
uname='woshinidaye'pwd='qunidedaye'username=input('username:')password=input('password:')if username==uname and password==pwd: print('welcome %s logging...'%uname)else: print('Incorrect username or password!')
Knowledge point:
--- Variable. Uname and pwd variables are used as an object to store user names and passwords;
The username and password variables are used as an object to store user input content.
--- "Input method. Accept user input.
--- "If-else judgment.
--- "% S placeholder. Use the variable uname to fill this position.
2. while loop, play a guess digital game!
age=22count=0while count<3: guess_age=int(input('guess it:')) if guess_age==age: print('Yes,you get it!') break elif guess_age>age: print('You have a problem in your eyes,guess younger!') else: print('Good boy,but guess oldder!') count+=1else: print('You have guess too many times,Go away!')
Knowledge point:
--- "While loop. Count <3, loop three times, jump out of the loop.
--- "If-elif-else judgment.
--- Break. Directly exit the loop.
3. for Loop. Change the posture to continue guessing.
-------------- Don't worry! Go to the foreplay and learn the for loop ----------------------
for i in range(10): print(i)
--- "The simplest for loop, loop 10 times, print all elements.
for i in range(0,10,2): print(i)
--- "Starts from 0 and repeats for 10 times. The step size is 2. It is a dozen times apart (from the mountains ).
for i in range(0,5): if i<3: print(i) elif i==3: continue else: print(i) print('hahhaha...')
--- "Continue jumps out of this loop and continues the next loop, so 3 does not print.
for i in range(5): print('For i loop'.center(20,'-'),i) for j in range(5): print('For j loop:',j) if j>2: break
--- "Nested loop. Loop 5*4 times, j = 3 will also print out, do not want to print "j = 3", then you change the condition to "j = 3...
-------------- Finally entered the topic. I'm so excited !!! ----------------------
age=22for i in range(3): guess_age=int(input('guess it:')) if guess_age==age: print('Yes,you get it!') break elif guess_age>age: print('You have a problem in your eyes,guess younger!') else: print('Good boy,but guess oldder!')else: print('You have guess too many times,Go away!')
--- Similar to the while LOOP, you do not need to define a variable as a counter.
4. For the three parameter passing methods, select Ren Jun.