Python (a) Beginners small experiment __python

Source: Internet
Author: User

Actual inspection

__author__ = ' Frank '

temp = input ("Input number:")

guess = Int (temp)

If guess = 8:

Print (' Right is 8 ')

Print ("Yea,very good,you won!")

Else

Print ("Unfortunate,you are wrong!")

Print (' Right is 8 ')

Print ("Game over!!!")

------------------------------------------------------------------------------

Experiment Two:

__author__ = ' Frank '

The "3"

Second = "4"

Third = i + second

Print (third) #这里的输出结果是34, which is the number 3 and 4, is not the real number "34"

i = 3

Second = 4

Third = i + second

Print (third) #这里输入的结果是7, that is, the meaning of 3+4=7, distinguished from the above section.

----------------------------------------------------------------------------

To sum up: print output constant After the parentheses if the "" number,

The actual value in the double quotation mark is entered, and if no double quotation mark () is applied, a variable is inside the bracket.

Which is the value of the output variable.

--------------------------------------------------------------------------------------------------------------- ---------

Experiment Three:

__author__ = ' Frank '

Print (' ' line1\nline3 ') #这里的 \ n Represents a newline

Print (' temp ')

The direct output of print ("C:\\i ' Am Tao") #这是print ("")

Print (' c:\\i\ ' am Tao ') #这里是print (') single quotation mark, internal need to use the escape character, backslash \

Print ("hello\n" * 3) #连续输出3次, no output.

So the result of experiment two is:

Line1

Line3

Temp

C:\i ' Am Tao

C:\i ' Am Tao

Hello

Hello

Hello

--------------------------------------------------------------------------------------------------------------- -

Experiment Four:

__author__ = ' Frank '

Import Random

Secret = Random.randint (1,10)

temp = input ("Please give Me anumber...\n")

guess = Int (temp)

Count = 0

While Guess!= secret:

If count== 0 and guess > secret:

Print ("It ' s too big!")

If count== 0 and guess < secret:

Print ("It ' s too small!")

Temp =input ("Please give me a number again...\n")

Guess =int (temp)

Count +=1

If count> 2:

Print ("Because you are wrong by four,so break.")

Break

If guess== secret:

Print ("Yes,you are right!")

Print ("haha~~~")

Else

Ifguess > Secret:

Print ("It ' s very big!")

Else

Print ("It ' s very small!")

Print ("Game over!!!")

#第2行是调用random的随机函数库
#第3行是指定random的随机函数库的取值的范围randint (1,10)
#第6行的count = 0 refers to the count, which is the number of times the number is entered. and the relative 14th line of Conut + 1 means count= Conut + 1,
#即每输入一次count的值就会 +1

--------------------------------------------------------------------------------------------------------------- -----------------

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.