Python(一)初學小實驗__Python

來源:互聯網
上載者:User


__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!!!")

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

實驗二:

__author__ = 'Frank'

first = "3"

second = "4"

third = first + second

print(third) #這裡的輸出結果是34,也就是3和4並列出來的數字,並不是真正的數字“34”

 

first = 3

second = 4

third = first + second

print(third) #這裡輸入的結果是7,也就是3+4=7的意思,區別於上面的部分。

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

綜上所述:print輸出常量後面的括弧內如果加“”號,

則表示輸入雙引號內的實際數值,而如果不加雙引號(),則括弧內的是一個變數。

也就是輸出變數的值。

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

實驗三:

__author__ = 'Frank'

print('''line1\nline3''') #這裡的\n表示換行

print('temp')

print("c:\\i'am tao") #這是print("")的直接輸出內容

print('c:\\i\'am tao') #這裡是print('')的單引號,內部需要使用到逸出字元,反斜線\

print("hello\n" * 3) #連續輸出3次,沒輸出一次就換行

那麼實驗二的結果就是:

line1

line3

temp

c:\i'am tao

c:\i'am tao

hello

hello

hello

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

實驗四:

__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是指的計數,也就是輸入數位次數。而相對的第14行的conut += 1的意思是count= conut + 1,
#即每輸入一次count的值就會+1

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.