-1

My code is

#import random intger
import itertools, random
#as how many cards you want delt
deck=input('Enter how many cards you want delt.')
#imports the list of the card symbol
card=list(itertools.product(range(1,14), ["Spade", "Heart", "Diamond", "Club"]))
#Picks a random card number.
random.shuffle(card)
print("You drew these cards:")
for i in range(deck):
  print(card[i][0], "of", card[i][1])
print("")
print("11s are jacks. 12s are queens. 13 are kings. 1 are aces.") 

But anytime I put in a number like 5 it breaks and says Traceback (most recent call last:) File "main.py", line 10, in for i in range(deck): TypeError: 'str' object cannot be interpreted as an integer

Floffy
  • 1
  • 2

2 Answers2

0

That is because the input you give is treated as a string. You can try: for i in range(int(deck)): to make sure the input is treated as a integer.

JarroVGIT
  • 4,291
  • 1
  • 17
  • 29
0

deck=int(input('Enter how many cards you want delt.')). Input is always str cast it to number if you are entering numbers

crackaf
  • 492
  • 2
  • 11