Python Forum
Blackjack total from string HW
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blackjack total from string HW
#2
All you have to do is to convert the numbers by using str() function to strings and then concatenate them by using

python 2.x
num = 4
maxnum = 14
spades = 3
print "Player Hand Total is "+str(num)+"/"+str(maxnum)+" with Ace of Hearts and "+str(spades)+" of Spades"
python 3.x
num = 4
maxnum = 14
spades = 3
print("Player Hand Total is "+str(num)+"/"+str(maxnum)+" with Ace of Hearts and "+str(spades)+" of Spades")
BUT in your case i would use something like:
( you dont need to use str() because it will already be given as a string )
lst = ['AH','3S']

# python 2.7
print "Player Hand Total is "+(lst[1][0])+" Spades"

# python 3.x
print("Player Hand Total is "+(lst[1][0])+" Spades")
in this case [1] is for accessing the second item which is 3S and [1][0] is for accessing the first string-element of 3Swhich is '3'
Reply


Messages In This Thread
Blackjack total from string HW - by ichistarr - Apr-27-2017, 10:06 AM
RE: Blackjack total from string HW - by idontreallywolf - Apr-27-2017, 12:51 PM
RE: Blackjack total from string HW - by snippsat - Apr-27-2017, 03:17 PM
RE: Blackjack total from string HW - by snippsat - Apr-27-2017, 05:12 PM
RE: Blackjack total from string HW - by nilamo - Apr-27-2017, 05:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Blackjack unionjackandsally 4 2,715 Apr-27-2020, 08:39 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020