[問題] 請問怎麼解此題?
Instructions
On line 2, fill in the if statement to check if answer is greater than 5.
On line 4, fill in the elif so that the function outputs -1 if answer is less
than 5.
def greater_less_equal_5(answer):
if ________:
return 1
elif ________:
return -1
else:
return 0
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
這是codecademy的題目
想問if
return 1是什麼意思?
return -1又是什麼意思?
return 0又是什麼意思?
Tks!
--------------------------------
後來我解出來原來是因為他前面還有段說明
一直把answer當作要寫一個判斷式大於5或小於5
所以方向完全錯誤
Instructions
On line 2, fill in the if statement to check if answer is greater than 5.
On line 4, fill in the elif so that the function outputs -1 if answer is less
than 5.
def greater_less_equal_5(answer):
if answer>5:
return 1
elif answer<5:
return -1
else:
return 0
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
好吧
知道答案以後覺得真的蠻蠢的XD
但也沒有每題都答不出來拉.....
卡關才上PTT求救.....
請各位高手高抬貴手 ~
感恩
--
Every man for himself and God against them all.
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.221.60.128
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1433721315.A.6AF.html
→
06/08 08:47, , 1F
06/08 08:47, 1F
推
06/08 09:50, , 2F
06/08 09:50, 2F
→
06/08 09:50, , 3F
06/08 09:50, 3F
→
06/08 09:50, , 4F
06/08 09:50, 4F
......
那請問答案要填什麼?
推
06/08 11:19, , 5F
06/08 11:19, 5F
推
06/08 12:45, , 6F
06/08 12:45, 6F
能帶給你歡樂很高興
那可以提供一下答案嗎?
→
06/08 13:43, , 7F
06/08 13:43, 7F
推
06/08 14:53, , 8F
06/08 14:53, 8F
→
06/08 14:54, , 9F
06/08 14:54, 9F
→
06/08 17:24, , 10F
06/08 17:24, 10F
※ 編輯: femlro (106.1.185.58), 06/08/2015 17:57:18
※ 編輯: femlro (106.1.185.58), 06/08/2015 17:57:38
→
06/08 18:26, , 11F
06/08 18:26, 11F
= =我答出來
原來我的問題是我沒在比大小前面+answer這個變數
加上去就好了....
※ 編輯: femlro (106.1.185.58), 06/08/2015 18:28:23
※ 編輯: femlro (106.1.185.58), 06/08/2015 18:51:25
→
06/08 19:02, , 12F
06/08 19:02, 12F
python相關課程?
※ 編輯: femlro (106.1.185.58), 06/08/2015 19:07:04
推
06/08 20:23, , 13F
06/08 20:23, 13F
Python 近期熱門文章
PTT數位生活區 即時熱門文章