我目前正在学习Python五周,我正在尝试编写一个非常简化的Blackjack版本。我已接近完成,但我无法通过这个错误消息:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
以下是代码:
import random
print("Welcome to my Black Jack program! Let's play!\n")
def deal_card():
Jack = 10
Queen = 10
King = 10
Ace = 1
cards = [Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King]
drawn_card = cards[random.randrange(1, 13)]
return drawn_card
def get_player_score():
first_player_card = deal_card()
second_player_card = deal_card()
sum_player_cards = first_player_card + second_player_card
print ("Your card total is: ", sum_player_cards, ".", sep="")
while sum_player_cards < 21:
choice = int(input("Would you like to hit or stay? Enter 1 for 'hit' or 2 for 'stay'. "))
if choice == 1:
new_card = deal_card()
sum_player_cards = sum_player_cards + new_card
print ("Your new total is: ", sum_player_cards, ".", sep="")
elif choice == 2:
return()
else:
print("Please choose 'hit' or stay'.")
choice = input("Would you like to hit or stay? Enter 1 for 'hit' or 2 for 'stay'. ")
if sum_player_cards > 21:
return()
return int(sum_player_cards)
def get_dealer_score():
first_dealer_card = deal_card()
second_dealer_card = deal_card()
sum_dealer_cards = int(first_dealer_card + second_dealer_card)
while sum_dealer_cards <= 16:
another_dealer_card = deal_card()
sum_dealer_cards = sum_dealer_cards + another_dealer_card
if sum_dealer_cards > 16:
print("The dealer's card total is: ", sum_dealer_cards, ".", sep="")
return int(sum_dealer_cards)
def main():
player_score = get_player_score()
dealer_score = get_dealer_score()
if player_score > dealer_score and player_score <= 21:
print("You win!")
elif dealer_score > player_score and dealer_score <= 21:
print("The dealer wins!")
elif dealer_score <= 21 and player_score > 21:
print("You've gone bust! Dealer wins!")
elif dealer_score > 21:
print("The dealer busts! You win!")
main()
我只有五章进入从Python开始,第4版。所以我应该只使用前五章所涵盖的原则。
答案 0 :(得分:0)
好的,感谢@Evert和@Wiggy A.,我修复了project/app/src/main/jniLibs/armeabi/libffmpegutils.so
函数中的return
语句。我意识到我需要将语句更改为get_player_score
,而不是return 0
或return
。我认为return sum_player_cards
语句只能在函数定义结束时使用返回值。但它们也可用于return
,if
和elif
语句。感谢您的投入。