[英]python function giving undesired result
我是編程新手,我一直在學習和嘗試 go 的基礎知識,但我堅持使用下面的代碼,無法真正弄清楚它有什么問題。我沒有得到所需的 output。
def sho(cards):
global num
num = 0
for card in cards:
print(card)
if 0 < card < 7:
num+=1
else:
num-=1
return num
ace = [1, 6 ]
print(sho(ace))
這是你要找的嗎?
def sho(cards):
global num
num = 0
for card in cards:
print(card)
if 0 < card < 7:
num+=1
else:
num-=1
return num
ace = [1, 6 ]
print(sho(ace))
Output:
1
6
2
def sho(cards):
num = 0
for card in cards:
print(card)
if 0 < card < 7:
num+=1
else:
num-=1
return num
ace = [1,6,8,9]
sho(ace)
嘗試上面的代碼行。 它應該返回你 output = 1,我覺得你正在尋找。 如果您在這種情況下需要不同的 output,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.