-1

Code:-

def displayHand(hand):
    for letter in hand.keys():
       for j in range(hand[letter]):
         print letter,              # print all on the same line
    print                               # print an empty line

hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1}

print displayHand(hand)

Output:-

a i m l l q u
None

Req Output:-

a i m l l q u

Kindly give a logical solution.

salil vishnu Kapur
  • 660
  • 1
  • 6
  • 29

3 Answers3

3

displayHand returns nothing. Just remove the print of the end of your code and it will work.

def displayHand(hand):
    for letter in hand.keys():
       for j in range(hand[letter]):
         print letter,              # print all on the same line
    print                               # print an empty line

hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1}

displayHand(hand)

Output:

a i m l l q u
Avión
  • 7,963
  • 11
  • 64
  • 105
1

Your function does not return anything thus when you print the result of the function it prints None

displayHand(hand) # execute the function without printing the result, in this case None
Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
1

displayHand() function does not return anything, hence when you do -

print displayHand(hand)

This actually prints None , since displayHand() did not return anything. Just call it as normal without the print -

displayHand(hand)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176