所以要開始編碼,我必須要求用戶輸入。他們必須像這樣放置4張牌
A-S,A-H,A-C,A-D
然后我會根據他們的輸入創建一個串列。它應該從他們的輸入中獲取第二個元素,然后是第四個元素
4cards = input()
List1 = []
List1.append(4cards[1], 4cards[3])
List1pair = ', '.join(P2)
print 'List1 cards: {0}.format(List1pair)'
這應該或者我希望它列印出來(我還沒有檢查)
List1 cards: A-H,A-D
但我的代碼回傳語法錯誤“SyntaxError:無效語法”
4cards = input()
我該如何解決這個問題?
uj5u.com熱心網友回復:
“SyntaxError: invalid syntax” 顯示,因為變數名不能以數字開頭。您可以使用four_cards 而不是4cards。
four_cards = input()
uj5u.com熱心網友回復:
您不能使用數字前 4 卡。使用變數 IE _4cards
_4cards = input()
List1 = []
List1.append(_4cards[1], _4cards[3])
List1pair = ', '.join(P2)
print ('List1 cards: {0}.format(List1pair)')
uj5u.com熱心網友回復:
嗨,由于變數的名稱,您收到錯誤的原因是4cards 我們不能將其用作變數名稱,它以數字開頭,因此您可以使用FourCards , Cards4 e.t.c
uj5u.com熱心網友回復:
變數不能以數字開頭,并且在 python3 列印函式中帶有括號:print(statement)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/530949.html
上一篇:誰能解釋如何解決這個問題
