today, The main learning is about the second speaking of the guessing number game improvement, in the course of the main learned the following points of Knowledge:
Comparison operators for 1:python
Use of 2:if and ELSE statements
3:while Cycle
Use of 4:and
5: Simple Module Reference (this course is a reference to Random)
1, There are several comparison operators for python, as Follows:
1 python comparison operator 2 3 > left greater than right 4 >= left greater than equals right 5 < left less than right 6 <= left less than equals right 7 = left equals right 8! = Left not equal to right
Note : The symbols used are in the English IME state
Use of the 2.if and else statements:
Note : The colon (:) after if and else
temp = Raw_input ("Please enter your age, I can guess your favorite singers:") Guess=int (temp)if0 <= Guess <= 30: ifGuess <= 15: Print("Tfboy") Else: Print("Jay")Else: Print("This is not your time, we have a generation gap! ")
The above code also contains nesting, please Note.
The use of 3,while.
We still use the code above to note the position and condition of the While.
temp = Raw_input ("I can guess the pop star you like, you want to try It? Reply 1 to continue, reply 0 to reject:") Guess=int (temp) while1 >0:temp= Raw_input ("Please enter your age, I can guess your favorite singers:") Guess=int (temp)if0 <= Guess <= 30: ifGuess <= 15: Print("Tfboy") Else: Print("Jay") Else: Print("This is not your time, we have a generation gap! ")
The above code needs to be improved, such as the termination of the program, as well as the reply 1 after the continuation and reply 0 after the rejection, this is only to investigate the simple use of while.
4. References to Modules
ImportRandomsecret= Random.randint (1,10)Print("............... I love fish c ... ......") Temp= Input ("Guess what the Little turtle thought of the numbers:") Guess=int (temp) whileguess! =secret:temp= Input ("oops, wrong guess, please re-enter it:") Guess=int (temp)ifGuess = =secret:Print("are you a worm in the heart of a little turtle? ") Print("guess it's not a reward, huh! ") Else: ifGuess >secret:Print("elder brother, Big has been big ~ ~ ~") Else: Print("brother, small, small, ~ ~ ~")Print("Game over, No Play ~ ~")
This code is copied by the video author, I will not (claw machine ah), Note the reference to the module here
5. After-school Assignments
First question: The original guess number game is required to be improved, so that it has only three opportunities.
ImportRandomsecret= Random.randint (1,10)Print('------------------i Love fish c studio------------------') Temp= Input ("guess which number the turtle is thinking now:") Guess=int (temp) i= 1 whileguess! = Secret andI < 3: Temp= Input ("oops, wrong guess, please re-enter it:") Guess=int (temp) i= i + 1ifGuess = =secret:Print("I grass, you are a small turtle in the heart of the worm?! ") Print("well, there's no reward for guessing! ") Else: ifGuess >secret:Print("elder brother, Big has been big ~ ~ ~") Else: Print("hey, small, Small.")Print("game over, No play ^_^")
Question Two: Requirements
Source Code Attached:
temp = Raw_input (" Please enter an integer:"== 1 while number : Print (i) = i + 1 = number-1
Question Three: Requirements
(read The original answer, still do not understand,) source code attached
temp = input ('Please enter an integer:') number=int (temp) whilenumber:i= Number-1 whileI:Print(' ', end ="') I= I-1J= number whileJ:Print('*', end ="') J= J-1Print() number= Number-1
Proper noun explanation: short circuit logic
If A and B: #如果a是false, then skip B's judgment and result directly false
If a or B: #如果a为true, then skip B's judgment, Direct True
Little Turtle Python Video IV (notes and after-school exercise answers)