Python Basics 2

Source: Internet
Author: User
Tags logical operators password book

One formatted output

The first of these methods
name1 = input ("Please enter Name:")
Age1 = input ("Please enter Age:")
Hobby1 = input ("Hobby is:")
msg = "My name is%s, this year%d years, hobby is%s"% (Name,int (age), hobby)
Print (msg)

The second method of
name1 = input ("Please enter Name:")

Age1 = input ("Please enter Age:")
Hobby1 = input ("Hobby is:")
msg = "I'm called% (name) s, year% (age) s, hobby is% (hobby) S"%{"name": name1, "age": Age1, "hobby": hobby1}
Print (msg)



Precedence of two-logical operators


() >not>and>or parentheses first not second and third  or IV
Print (1>2 and 3>4 or 4<5)
Print (not 9>0 and (3<5 or 8>7) and 7>6 or 3>8)



X and Y are true if both sides are numbers output x otherwise output Y
Print (1 and 8)
Print (7 and 8)
Print (0 and 8)
Print (0 and 9)


or opposite and
Print (1 or 8)
Print (7 or 8)
Print (0 or 8)
Print (0 or 9)

Three-coded

War period:
A telegram, a high-low frequency, is actually 01010101.
Today 0000 0001
Late 0000 0101
Hi 0000 0111
Go 0000 1001

00000001 00000101 00000111 00001001

Computer:
storing files, or transferring files, is actually 010101010
The beginning of the computer creation, the USA, the binary,

Password Book:
Ascii
00000001
01000001 01000010 01000011 ABC

Because there are a lot of languages in the world, ASCII is not enough to store so many correspondence, creating a Super cipher Ben: Universal Unicode
8-bit = = 1 bytes.
Hello h a character, e a character, and he is not a character.
China: Medium is a character, the state is a character.
Unicode:
At the beginning of creation, 16-bit, 2-byte, representing a character.
English: A b C six bytes one English 2 bytes
Chinese Chinese four bytes one Chinese with 2 bytes
Change to 32-bit, 4-byte, representing one character.
A 01000001 01000010 01000011 00000001
b 01000001 01000010 01100011 00000001
Medium 01001001 01000010 01100011 00000001
Waste of resources.
To upgrade Unicode: Utf-8
Utf-8 uses a minimum of 8 digits to represent a character.
English: 8-bit, 1-byte representation.
European text: 16-bit, two-byte represents a character.
Chinese, Asian text: 24-bit, three-byte representation.
Utf-16 with a minimum of 16 digits.

Gbk
National standard, can only be used by the Chinese, a Chinese with 16 bits, two bytes of expression.

Unit conversions:
8 bit bit 8bit = = 1bytes
1024bytes = = 1kB
1024KB = = 1MB
1024MB = = 1GB
1024GB = = 1TB


Four jobs

The

Determines the true,false of the following logical statements.
1), 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6             &N Bsp    true
2) not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6       &N Bsp   False
2, the values of the following logical statements are calculated.
1), 8 or 3 and 4 or 2 and 0 or 9 and 7                       &NB Sp                        8      
2), 0 or 2 and 3 and 4 or 6 and 0 or 3                                                       4
3 What are the following results?                          ,         &NB Sp              

1), 6 or 2 > 1 6
2), 3 or 2 > 1 3
3), 0 or 5 < 4 False
4), 5 < 4 or 3 3
5), 2 > 1 or 6 Ture
6), 3 and 2 > 1 ture
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. Brief description of variable naming conventions

1 Alphanumeric underline composition

2 Number cannot start

3 Not recommended in Chinese

4 to be descriptive

5 can't be too long

6 Suggested Hump and underline

7 can't use keywords
5. Name = input (">>>") what is the data type of the name variable? String type
6. What is the basic structure of the IF condition statement? If condition:

Conclusion

7. While loop statement basic structure? While condition:

Conclusion
8. Write code: Calculate 1-2 + 3 ... + 99 The sum of all the numbers except 88?

A = 1
sum = 0
While a<100:
If a%2==1:
sum = Sum+a
A = A+1
Elif a%2==0:
If a = = 88:
A+=1
Continue
sum = sum-a
A = A+1
Print (sum)


9. Login (three chance of error) and display the number of remaining errors (hint: Format the string) for each loss

A = 3
While a > 0:
Name = input ("Please enter user name:")
Password = input ("Please enter password:")
If name = = "Alex" and password = = "123":
Print ("Login Successful")
Break
Else:a-= 1
b = "%d times left Today"% (a)
Print (b)
If a = = 0:
Print ("The number of logins is exhausted today, please try again tomorrow")
Else:print ("User name or password is wrong, re-enter")

10. Describe the ASCII, Unicode, utf-8 encoding relationships?

ASCII is the first, the rest is based on its perfect, ASCII with 8 bits, a byte to represent a character

Unicode is also called the universal code starting with 16-bit two bytes representing a character, but cannot represent a character that is completely later represented by 32-bit four bytes

Utf-8 is optimized for Unicode, and he uses the fewest bits to represent a character, such as English with a 8-bit European 16-bit representation in Chinese with 24-bit representation.

11. Describe the relationship between bits and bytes? 8-bit = = one byte


12. "The Boy"? 6 of UTF-8 codes?? A byte? Make? GBK code 4? bytes?


13. Create Fun Template program requirements: Wait for the user to lose the name, place, hobby, according to the user's
The name and the hobby go into? Any reality such as: love and amiable xxx, favorite in the xxx place??

Name = input ("Please enter Name:")
do = input ("Please enter what to do:")
Local = input ("Please enter location:")
msg = "Dear%s,%s, like dry%s" % (Name,local,do)
Print (msg)



14. Wait for the user to lose content, to detect the loss of the contents of the content contains sensitive characters? If there is
Sensitive characters prompt "There are sensitive characters please lose again", and allow the user to re-lose and print. Sensitive
Sense character: "? Pink", "Hammer"

While True:
A = input ("Please enter a word;")
If "Hammer" in A or "matte" in A:
Print ("Contains sensitive characters, please reenter")
Continue
Else:break


15. Single comment and multi-comment? Add multiple lines of comment in the middle of #后加单行注释 "
16. Describe the difference between Python3 and Python2 you know?
17. Look at the code writing results:
A = 1>2 or 4<7 and 8 = = 8
Print (a) False


18.continue and break difference?

Continue end this cycle and start again

Break ends and jumps out of this loop

Day3 Dictation Code:
The conversion relationship between BIT,BYTES,KB,MB,GB,TB. 8bie==1byte 1024byte==1kb 1024kb ==1mb 1024mb==1gb 1024GB==1TB
UNICODE,UTF-8,GBK, each encoded in English, Chinese, respectively, in a few bytes.

Unicode  English 4  Chinese  
Utf-8 English 1 Chinese 2
GBK English 2 Chinese 2







Python Basics 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.