यह मेरा कोड नीचे है यह सही काम है लेकिन समस्या मेरे तर्क में है अगर मैंने उपयोगकर्ता से पूछा कि क्या वह एक और कार्ड चाहता है तो खेल शुरू से ही फिर से लोड हो जाए तो आप इसे वहां आजमा सकते हैं https://replit.com/@KamalSalm/blackjack-start-1#main.py अगर आप चाहें तो

  • कोड सही काम करता है लेकिन समस्या उपयोगकर्ता से दूसरे कार्ड के लिए पूछी जाती है

    import random
import art
from replit import clear

############### Blackjack Project #####################

#Difficulty Normal 😎: Use all Hints below to complete the project.
#Difficulty Hard 🤔: Use only Hints 1, 2, 3 to complete the project.
#Difficulty Extra Hard 😭: Only use Hints 1 & 2 to complete the project.
#Difficulty Expert 🤯: Only use Hint 1 to complete the project.

############### Our Blackjack House Rules #####################

## The deck is unlimited in size. 
## There are no jokers. 
## The Jack/Queen/King all count as 10.
## The the Ace can count as 11 or 1.
## Use the following list as the deck of cards:
## cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
## The cards in the list have equal probability of being drawn.
## Cards are not removed from the deck as they are drawn.
## The computer is the dealer.

##################### Hints #####################

#Hint 1: Go to this website and try out the Blackjack game: 
#   https://games.washingtonpost.com/games/blackjack/
#Then try out the completed Blackjack project here: 
#   http://blackjack-final.appbrewery.repl.run
#deck
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
#logo blackjack
def logo():
  """show logo"""
  print(art.logo)
#user cards
def add_card():
  return random.choice(cards)
  


#the final cards
the_cards ={}


game_on = True
while game_on:
  user_response = input("Do you want to play a game of Blackjack? Type 'y' or 'n': ").lower()
  if user_response == "y":
    clear()
    the_cards["user_cards"] = [add_card() , add_card()]
    total_user = sum(the_cards['user_cards'])
    the_cards["com_cards"] = [add_card()]
    total_com = sum(the_cards['com_cards'])
    print(art.logo)
    print(f"   your cards: {the_cards['user_cards']}, current score is :{total_user} ")
    print(f"   computer is first card is {the_cards['com_cards']}")
    #ask user if he want another card or pass
    if total_user == 21:
      print("game over you win it's blackjack")
      game_on = False
    elif total_user < 21 and total_com < 21:
      ask_user = input("would you choose another card ").lower()
      if ask_user == "y":
        total_user += add_card()
        if total_com > 13:
          total_com += add_card()
          if total_com == 21:
            print("game over it's blackjack com win")
          
          elif total_user > total_com:
            print("you have won upper hand")
          elif total_user < total_com:
            print("you have lost not good hand")

      
      elif ask_user =="n":
        if total_user > total_com:
          print("you have won your cards beat com")
        elif total_user < total_com:
          print("you have lose com has bigger hands")
    
    else:
      if total_user > 21:
        print("game over you lose it is over 21")
      elif total_com > 21:
        print("you win computer cards over 21 ")


    


  elif user_response == "n":
    print("game over you can try again if you like")
    game_on = False

  else:
    print("you type it wrong try again")
1
python1990 27 नवम्बर 2021, 11:28
अद्यतन _ मुझे लगता है कि मैं उस समस्या को समझता हूं जिसे मैंने इसे अद्यतन करने के बाद इसे अद्यतन किया था, तर्क कुल कॉम में था> 13 मैंने इसे फिर से संपादित किया लेकिन यहां तक ​​​​कि यह काम नहीं करता है
 – 
kamal java
27 नवम्बर 2021, 11:46

1 उत्तर

सबसे बढ़िया उत्तर

पूरा समाधान देने के बिना, मैं सिर्फ आपके कोड को 2 लूप के साथ रिफैक्टर करने का सुझाव देता हूं, गेम प्ले को दूसरे कार्ड से अलग करने के लिए:

# the final cards
the_cards = {}

launch_game = 'y'
while launch_game == 'y':
    user_response = input("Do you want to play a game of Blackjack? Type 'y' or 'n': ").lower()
    game_on = True
    total_user = 0
    total_com = 0
    while user_response == 'y' and game_on:
        if total_user == 0:
            the_cards["user_cards"] = [add_card(), add_card()]
            total_user = sum(the_cards['user_cards'])
            the_cards["com_cards"] = [add_card(), add_card()]
            total_com = sum(the_cards['com_cards'])
        else:
            the_cards["user_cards"].append(add_card())
            total_user = sum(the_cards['user_cards'])
            the_cards["com_cards"].append(add_card())
            total_com = sum(the_cards['com_cards'])

        print(f"   your cards: {the_cards['user_cards']}, current score is :{total_user} ")
        print(f"   computer's card: {the_cards['com_cards']}, current score is :{total_com} ")

        game_on = False
        if total_user == 21:
            print("game over you win it's blackjack")
            continue
        if total_com == 21:
            print("game over you lose it's blackjack for computer")
            continue
        if total_user > 21:
            print("game over you lose it is over 21")
            continue
        if total_com > 21:
            print("you win computer cards over 21 ")
            continue



        ask_user = input("would you choose another card ").lower()
        if ask_user == "y":
            game_on = True
            continue
        else: #and if total_user == total_com?
            if total_user > total_com:
                print("you have won your cards beat com")
            elif total_user < total_com:
                print("you have lose com has bigger hands")

आपके लिए अपने कोड में समस्या को फंसाना आसान होगा!

0
Frenchy 27 नवम्बर 2021, 13:02
Omg मैं अब समझ गया हूँ कि आप एक प्रतिभाशाली हैं बहुत बहुत धन्यवाद मुझे पता है कि क्या करना है
 – 
kamal java
27 नवम्बर 2021, 13:43