小甲魚Python第四講

來源:互聯網
上載者:User

標籤:secret   有獎   表達   分享   應該   工作室   love you   dom   color   

1while語句中,當條件為真時,它會一直迴圈下去,比如下面的例子,不過可以用Ctral + C來強制結束

while ‘C‘:    print("i love you")

 

2.觀察列印次數

i = 10while i > 0:    print("i love you")    i = i - 1

列印10次 ‘i love you’

 

3.注意and的用法(表示兩邊都為真),請寫出與10<a<19等價的運算式

10 < a < 1910 < a and a < 19

 

4.短路邏輯

籠統的說,短路邏輯值得是在一個邏輯中,只判斷前半部分,只要前半部分可以確定結果,就不會判斷邏輯的後半部分。

 

5.Python3中,一行可以書寫多條語句嗎?

可以;

print(‘asdf‘);print(‘asdf‘)

 

6.python3中,一個語句可以分成多行書寫嗎?

可以,可以使用反斜線或括弧分解成幾行

print\

("hh")

 

7.and or

x or y  ---if x is false,then y,else x

x and y --if x is false,then x,else y

not x--- if x if false, then True,else False

 

8.注意while中的條件,即0為假

num = int(input("請輸入一個整數:"))i = 0while num:    i = i + 1    num = num - 1    print(i)

另附小甲魚的

temp = input(‘請輸入一個整數:‘)number = int(temp)i = 1while number:    print(i)    i = i + 1    number = number - 1

 

9.(抄襲小甲魚的)

temp = input(‘請輸入一個整數:‘)number = int(temp)while number:    i = number - 1    while i:        print(‘ ‘, end = ‘‘)        i = i - 1    j = number    while j:        print(‘*‘, end = ‘‘)        j = j - 1    print()    number = number - 1

10.(抄襲小甲魚的)

import randomtimes = 3secret = random.randint(1,10)print(‘------------------我愛魚C工作室------------------‘)# 這裡先給guess賦值(賦一個絕對不等於secret的值)guess = 0# print()預設是列印完字串會自動添加一個分行符號,end=" "參數告訴print()用空格代替換行# 嗯,小甲魚覺得富有創意的你應該會嘗試用 end="JJ"?print("不妨猜一下小甲魚現在心裡想的是哪個數字:", end=" ")while (guess != secret) and (times > 0):    temp = input()    guess = int(temp)    times = times - 1 # 使用者每輸入一次,可用機會就-1    if guess == secret:        print("我草,你是小甲魚心裡的蛔蟲嗎?!")        print("哼,猜中了也沒有獎勵!")    else:        if guess > secret:            print("哥,大了大了~~~")        else:            print("嘿,小了,小了~~~")        if times > 0:            print("再試一次吧:", end=" ")        else:            print("機會用光咯T_T")print("遊戲結束,不玩啦^_^")

小甲魚Python第四講

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.