Python Forum
Blackjack total from string HW
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blackjack total from string HW
#5
(Apr-27-2017, 04:47 PM)idontreallywolf Wrote: @snippsat Define "not nice"
num = 4
maxnum = 14
spades = 3

# Not nice
print("Player Hand Total is "+str(num)+"/"+str(maxnum)+" with Ace of Hearts and "+str(spades)+" of Spades")

# String formattting {} was new in Python 2.6
print("Player Hand Total is {}/{} with Ace of Hearts and {} of Spades".format(num,maxnum,spades))

# New in Python 3.6 f-string it's what we all be using in future
print(f"Player Hand Total is {num}/{maxnum} with Ace of Hearts and {spades} of Spades")
Output:
Player Hand Total is 4/14 with Ace of Hearts and 3 of Spades Player Hand Total is 4/14 with Ace of Hearts and 3 of Spades Player Hand Total is 4/14 with Ace of Hearts and 3 of Spades
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 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,694 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