Whenever I try to assign a string to an int I get the following message:
Traceback (most recent call last):
File "poker.py", line 61, in
test_value1 = int (test_value)#convert the string to int
TypeError: int() argument must be a string or a number, not 'list'
My problem is on the very last line of code everything else works fine.
``
import random
list_suits=['H','S','D','C']#Heart,Spade,Diamond,Clubs
list_values=['1','2','3','4','5','6','7','8','9','10','11','12','13']
final_list = []
for i in range (0,4):
for j in range(0,13):#adding card values and suits together
final_list.append(list_suits[i]+'_'+list_values[j])
random.shuffle(final_list)
print 'Cards Dealt\n'
print 'card1',final_list[0]
print 'card2',final_list[1]
print 'card3',final_list[2]
print 'card4',final_list[3]
print 'card5',final_list[4]
dealt_suit_and_value=[]
for m in range(0,5):
dealt_suit_and_value.append(final_list[m].split("_"))
hold_value=[]
hold_suit=[]
for n in range(0,5):
c=dealt_suit_and_value[n]#value section
c=c[1:]
#print 'C is:',c
#c = int(c)
hold_value.append(c)
print '****Value:',hold_value[n]
d=dealt_suit_and_value[n]#suit section
d=d[:-1]
#print 'D is:',d
hold_suit.append(d)
print 'Suit',hold_suit[n]
test_value = hold_value[0] #assign the first item in the list to a variable
print 'test value',test_value #to check the value of the variable
test_value1 = int (test_value)#convert the string to int
``
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Found the problem.