'''
1. Brief description of variable name specification
(1) The variable must consist of letters, numbers, and underscores.
(2) A variable cannot be the beginning of a number, nor can it be a purely numeric composition.
(3) A variable cannot be a python keyword.
(4) The variable name should be meaningful, not casually blind.
(5) The variable should not be too long.
(6) Do not use Chinese for variables.
(7) Case-sensitive.
(8) It is recommended to use hump or underline name
'''
"""
2.name = input (">>>") what is the data type of the name variable?
The name variable is the STR string data type
Name = input (">>>")
Print (Type (name))
Here are the output results
>>>lsy
<class ' str ' >
Process finished with exit code 0
"""
"""
The basic structure of a 3.if conditional statement?
Divided into four types, the basic structure is written and illustrated below.
One
If condition judgment:
Code Block 1
Else
Code Block 2
Execution steps: Determine whether the condition is established, if the condition is true, execute code block 1, if not, execute code block 2.
Example:
Number = input ("Please enter the numbers you are comparing:")
if int (number) >= 20:
Print ("The number you entered is greater than or equal to 20")
Else
Print ("The number you entered is less than 20")
Let's verify that entering 20 and 12 respectively finds the result to be right.
Please enter the number you are comparing: 20
The number you entered is greater than or equal to 20
Please enter the number you are comparing: 12
The number you entered is less than 20
Two
If condition judgment:
code block
code block
Execution process: Executes the code block if the condition is true. If it doesn't, it won't be executed.
Example:
Number = input ("How much money is still in the pocket:")
if int (number) >= 3000:
Print ("Make a drip Home")
Print ("Home")
Output Result:
How many money:500 are there in the pocket?
Go home
How many money:3100 are there in the pocket?
Take a drip home
Go home
Three
If condition 1:
Code Block 1
Elif Condition 2:
Code block 3
。。。
Else
Code block n
Execution process: If condition 1 is established, execute code block 1. Otherwise, if condition 2 is established, code block 2 is executed. According to this ... Until the end is not established, execute code N.
(Only one block of code is executed)
Example:
Number = input ("How many points have been tested in this exam:")
if int (number) >= 95:
Print ("Sea Bottom Fishing")
elif Int (number) >= 85:
Print ("Door-string")
elif Int (number) >= 75:
Print ("Go home to eat noodles")
Else
Print ("Go Home Hungry")
Validation results:
How many points were taken in this exam: 60
Go home and starve.
How many points were taken in this exam: 96
Sea fishing at the entrance
How many points were taken in this exam: 78
Go home and eat noodles.
How many points were taken in this exam: 89
The door is a bunch of children
Iv. nesting
If condition judgment:
If condition judgment:
Code 1
Else
Code 2
Else
Code n
Example
House = input ("Do you have a room:")
If House = = ' have ':
Car = input ("Do you have a car:")
if car = = ' have ':
Money = input ("Do you have a deposit:")
If money = = ' have ':
Print ("You're the one I'm waiting for, drink a bottle of champagne.") ")
Else
Print ("No deposit, drink Sprite bar")
Else
Print ("Not even a car, drink a cup of boiled water")
Else
Print ("Where to go back and forth")
Validation examples:
Do you have a house: there
Do you have a car?
Do you have a deposit:
You're the one I'm waiting for, drinking a bottle of champagne.
Do you have a house: there
Do you have a car?
Do you have a deposit: no
There's no deposit, just a sprite.
Do you have a house: there
Do you have a car: no
Not even a car, drink a cup of boiled water
Do you have a house: no
Where do you go back and forth?
"""
"""
4. Print out the following content with print:
Wen can pen the world,
Wu can mount a horse and set the universe
Who wins with counsel,
The heroes of ancient and modern are only June.
Print ("'
Wen can pen the world,
Wu can mount a horse and set the universe
Who wins with counsel,
The heroes of ancient and modern are only June.
''')
Output results
Wen can pen the world,
Wu can mount a horse and set the universe
Who wins with counsel,
The heroes of ancient and modern are only June.
Process finished with exit code 0
"""
"""
5. Use the If statement to write the game with the guessing size:
Set an ideal number such as: 66, let the user enter a number, if the larger than 66, then the display is larger than the guess, if it is smaller than 66, then the result is smaller; only equals 66, the result is correct.
The simple point of the problem is this way, there is also a loss of 66 is entered until the input is correctly exited.
Number = input ("Enter the numbers you guessed:")
if int (number) > 66:
Print ("You guessed the result is big")
elif Int (number) < 66:
Print ("You guessed the result is small")
Else
Print ("Congratulations, you guessed it.") ")
Verify the results first, right?
Enter the number you guessed: 67
You're guessing the results are big.
Enter the number you guessed: 66
Congratulations, you guessed it.
Enter the number you guessed: 60
The result of your guess is small.
The second way of thinking
correct = 66
While True:
Number = input ("Enter a guessed digit:")
if int (number) > correct:
Print ("You guessed the result is big")
elif Int (number) < correct:
Print ("You guessed the result is small")
Else
Print ("Congratulations, you guessed it.") ")
Break
Let's verify that the results are correct.
Enter the number of guesses: 67
You're guessing the results are big.
Enter the number of guesses: 68
You're guessing the results are big.
Enter the number of guesses: 60
The result of your guess is small.
Enter the number of guesses: 66
Congratulations, you guessed it.
"""
"""
6. Prompt the user to enter his age, the procedure to judge.
If it is less than 10, hint little brat.
If it is greater than 10, less than 20, the adolescent rebellious child is suggested.
If it is greater than 20, less than 30, prompt to start qualitative, start to mix the society of the little brat.
If more than 30, less than 40, the hint to see Laotaibuxiao, feel married little fart child.
If it is greater than 40, less than 50, the home has a disobedient child.
If it is greater than 50, less than 60, prompt yourself to become an obedient old fart child immediately.
If it is greater than 60, less than 70, the hint of living a good old fart.
If more than 70, less than 90, the prompt life is almost over an old fart babe.
If more than 90, hint, goodbye to the world.
According to the question or two ways of solving one, only use if to judge the second, not only if the judge also use while loop
One
age = Int (input ("Please enter your Ages:"))
If age < 10:
Print ("Little brat")
Elif Age < 20:
Print ("Teenage rebellious Little brat")
Elif Age < 30:
Print ("Start qualitatively, start a mixed-up little fart Babe")
Elif Age < 40:
Print ("Look at the eldest brother, hurry to marry little fart Babe")
Elif Age < 50:
Print ("There's a naughty little fart in the house")
Elif Age < 60:
Print ("Turn yourself into a disobedient old fart babe")
Elif Age < 70:
Print ("Alive or good old fart babe")
Elif Age < 90:
Print ("The end of life an old fart babe")
Else
Print ("Goodbye to the World")
Two
While True:
age = Int (input ("Please enter your Ages:"))
If age < 10:
Print ("Little brat")
Elif Age < 20:
Print ("Teenage rebellious Little brat")
Elif Age < 30:
Print ("Start qualitatively, start a mixed-up little fart Babe")
Elif Age < 40:
Print ("Look at the eldest brother, hurry to marry little fart Babe")
Elif Age < 50:
Print ("There's a naughty little fart in the house")
Elif Age < 60:
Print ("Turn yourself into a disobedient old fart babe")
Elif Age < 70:
Print ("Alive or good old fart babe")
Elif Age < 90:
Print ("The end of life an old fart babe")
Else
Print ("Goodbye to the World")
"""
"""
7. Single-line comments and multiline comments
#井号就是单行注释
'''
Six single or double quotes is a multiline comment
'''
"""
"""
8. Describe the difference between python3x and python2x you know?
(1) The difference between the print function
(2) input in Python3 is obtained by str,python2 input int.
"""
"""
9. Prompt the user to enter the twist cane, to determine whether the user input is right, if yes, Ascension is really smart, if not, prompt you are xxx?
While True:
Print ("Please enter the Twist vine")
Name = input ("Please enter:")
If name = = ' Twist Vine ':
Print ("Really smart")
Else
Print ("Are you xxx?")
Please enter the Twist vine
Please enter: Mahuateng
Are you xxx?
Please enter the Twist vine
Please enter: Twist rattan
That's brilliant.
Please enter the Twist vine
Please enter:
"""
"""
10. Using while loop input 1 2 3 4 5 6 8 9 10
Number = 1
While True:
If number <= 10:
If number! = 7:
Print (number)
Number + = 1
Here are the results of the validation
1
2
3
4
5
6
8
9
10
"""
"""
11. Ask for 1-100 of all numbers and
Count = 1
sum = 0
While Count <= 100:
sum = sum + count
Count + = 1
Print (sum)
Verify that the results are correct
5050
"""
"""
12. Output all the odd numbers within 1-100.
Count = 1
While Count <= 100:
If Count% 2! = 0:
Print (count)
Count = Count + 1
"""
"""
13. Output all the even numbers within 1-100.
Count = 1
While Count <= 100:
If count% 2 = = 0:
Print (count)
Count = Count + 1
"""
"""
14. Ask for the 1-2+3-4+5...99 of all the numbers.
Number = 1
connt = 0
While number < 100:
If number%2 = = 0:
Connt = Connt-number
elif number%2 = = 1:
Connt = connt + number
Number + = 1
Print (CONNT)
"""
#以下是作业题
"""
Job: User Login
1. Three Retry opportunities
2. The number of errors left on the line each time the error is entered
name = ' Lisongyang '
Password = ' lsy123 '
Connt = 1
Print ("You have a total of three opportunities")
While Connt <= 3:
Username = input ("Please enter the correct user name:")
UserPassword = input ("Please enter the correct password:")
If username = = Name and UserPassword = = password:
Print ("Welcome, login is correct.") ")
Break
Else
Print ("Account or password input error")
Print ("You still have%d chances.") "% (3-CONNT))
Connt + = 1
"""
Getting started with Python-simple basic questions exercises