trouble with classes in python -


i getting error reads , no matter unable rid of code.

traceback (most recent call last):   file "c:\users\ian\desktop\blackjack.py", line 226, in <module>     main()   file "c:\users\ian\desktop\blackjack.py", line 225, in main     blackjack.playgame()   file "c:\users\ian\desktop\blackjack.py", line 145, in playgame     self.firstround()   file "c:\users\ian\desktop\blackjack.py", line 83, in firstround     a=self.dealer.hand.append(deckofcards.deal(deckofcards.shuffledeck)) attributeerror: type object 'deckofcards' has no attribute 'shuffledeck' 

the following actual code have written ( have changed great deal in order move error along can no longer figure out going on) want skim on , tell me obvious mistakes, sure there many, , apologize our professor doesn't teach use how things , expects know how.

from random import*   class card(object):     def __init__(self,suit,number):         self.suit=suit         self.number=number  class deckofcards(object):     def __init__(self,deck):         self.deck=deck         self.shuffledeck=self.shuffle()         #print(self.shuffledeck)     def shuffle(self):         #print('this shuffle function')         b=[]         count=0         while count<len(self.deck):             a=randrange(0,len(self.deck))             if not in b:                 b.append(self.deck[a])                 count+=1         return(b)      def deal(self):         if len(self.shuffledeck)>0:             return(self.shuffledeck.pop(0))         else:             shuffle(self)             return(self.shuffledeck.pop(0)) class player(object):     def __init__(self,name,hand,inout,money,score,bid):         self.name=name         self.hand=hand         self.inout=inout         self.money=money         self.score=score         self.bid=bid     def __str__(self):         x = self.name + ":\t"         x += "card(s):"         y in range(len(self.hand)):             x +=self.hand[y].face + self.hand[y].suit + " "         if (self.name != "dealer"):             x += "\t money: $" + str(self.money)         return(x)  class game(object):     def __init__(self,deck, player):         self.player=player(player,[],true,100,0,0)         self.dealer=player("dealer",[],true,100,0,0)         self.deck=deckofcards(deck)         self.blackjack= false #self.blackjacksearch()     def blackjacksearch(self):#this says there error moved because said needed in class getot function          if self.player.hand.gettot()==21:             return true         else:             return false         def firstround(self):         self.player.inout=true         self.player.hand=[]         self.dealer.hand=[]         a=self.dealer.hand.append(deckofcards.deal(deckofcards.shuffledeck))         print(a)         playerbid=int(input('how bet?'))         self.player.bid=playerbid     def playturn(self):         while self.player.blackjack!=true or hit=='yes':             print(self.player.hand)             a=self.player.hand.append(deal())             print('the card drew ' + str(a))             print(gettot())             hit=input('would hit? ')             if hit=='yes':                 return(self.player.hand.append(deal()))             else:                 return() #might need change         if self.player.blackjack==true:             print(self.player.name + " has blackjack ")         if hit=='no':             print (self.player.hand.gettot())     def playdealer(self):         while self.dealer.hand<17:             self.dealer.hand.append(deal())             dealerhand=self.dealer.hand.gettot() #confused             print(dealerhand)         if self.dealer.hand==21:             self.dealer.blackhjack=true         dealerhand1=self.dealer.hand.gettot()         print(dealerhand1)      def gettot(self,hand):         total=0         x in self.hand:             if x==card('h','a'):                 b=total+x                 if b>21:                     total+=1                 else:                     total+=11             if x==card('d','a'):                 b=total+x                 if b>21:                     total+=1                 else:                     total+=11             if x==card('s','a'):                 b=total+x                 if b>21:                     total+=1                 else:                     total+=11             if x==card('c','a'):                 if b>21:                     total+=1                 else:                     total+=11             else:                 total+=x         return(total)      def playgame(self):         play = "yes"         while (play.lower() == "yes"):             self.firstround()             self.playturn()             if self.player.blackjack == true:                 print(self.player.name + " got blackjack! ")                 self.player.money += self.player.bid * 1.5                 print (self.player.name + " has " + str(self.player.money))                 print("\n")                 self.player.inout = false             if self.player.score > 21:                 print(self.player.name + " lost tot of " + str(self.player.score))                 self.player.money -= self.player.bid                 print (self.player.name + " has " + str(self.player.money))                 print ("\n\n")                 self.player.inout = false             self.playdealer()             if self.dealer.blackjack == true:                 print("dealer got blackjack, dealer wins\n")                 self.player.money -= self.player.bid                 print("round\n")                 print("\t",self.dealer)                 print("\t",self.player)                 print("\t dealer has " + str(self.dealer.score) + ", " + self.player.name + " has " + str(self.player.score))             elif self.player.inout == true:                 print("round\n")                 print("\t",self.dealer)                 print("\t",self.player)                 print("\n\t dealer has " + str(self.dealer.score) + ", " + self.player.name + " has " + str(self.player.score))                 if self.dealer.score > 21:                     print("\t dealer lost total of " + str(self.dealer.score))                     self.player.money += self.player.bid                     print(self.player.name + " has " + str(self.player.money))                 elif self.player.score > self.dealer.score:                     print("\t" +self.player.name + " won total of " + str(self.player.score))                     self.player.money += self.player.bid                     print("\t"+self.player.name + " has " + str(self.player.money))                 else:                     print("\t dealer won total of " + str(self.dealer.score))                     self.player.money -= self.player.bid                     print("\t"+self.player.name + " has " + str(self.player.money))             else:                 print("round")                 print("\t",self.dealer)                 print("\t",self.player)                 if self.player.blackjack == false:                     print("\t "+ self.player.name + " lost" )                 else:                     print("\t "+self.player.name + " won!")              if self.player.money <= 0:                 print(self.player.name + " out of money - out of game ")                 play = "no"             else:                 play = input("\nanother round? ")                 print("\n\n")         print("\ngame over. ")         print(self.player.name + " ended " + str(self.player.money) + " dollars.\n")         print("thanks playing.  come soon!")    ls= [card('h','a'),card('h','2'),card('h','3'),card('h','4'),card('h','5'),card('h','6'),card('h','7'),card('h','8'),card('h','9'),card('h','10'), card('h','j'),card('h','q'),card('h','k'), card('s','a'),card('s','2'),card('s','3'),card('s','4'),card('s','5'), card('s','6'),card('s','7'),card('s','8'),card('s','9'),card('s','10'), card('s','j'),card('s','q'),card('s','k'), card('c','a'),card('c','2'),card('c','3'),card('c','4'),card('c','5'), card('c','6'),card('c','7'),card('c','8'),card('c','9'),card('c','10'), card('c','j'),card('c','q'),card('c','k'), card('d','a'),card('d','2'),card('d','3'),card('d','4'),card('d','5'), card('d','6'),card('d','7'),card('d','8'),card('d','9'),card('d','10'), card('d','j'),card('d','q'),card('d','k')]  '''tom=card('heart','queen') print(tom.suit) print(deckofcards(ls)) print(ls.suit)'''  def main():     x = input("player's name? ")     blackjack = game(ls,x)     blackjack.playgame() main() 

this line right 1 problem:

a=self.dealer.hand.append(deckofcards.deal(deckofcards.shuffledeck)) 
  • append returns none (regardless of append), a none
  • deckofcards refers class object, not instance of class. want use self.deck instead of deckofcards.

x==card('s','a'): isn't going work either. haven't defined __eq__ card object, comparisons don't work (you'll false).


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -