Here is the file:
Admiral,30,1
General,25,1
Colonel,20,2
Major,15,2
Captain,10,2
Lieutenant,7,2
Sergeant,5,4
Corporal,3,6
Private,1,10
I need to display the deck (in list form) and output how many cards there are. The last number in the file represents how many cards there are. So there is 1 Admiral card in the deck, 2 Colonel, 10 Private, etc.
Below is my code so far:
numFile = open("ranks.dat", "r")
#list fields
rankList = []
skillList = []
numberList = []
while True:
text = numFile.readline()
text = text.rstrip("\n")
if text=="":
break
info = text.split(",")
rankList.append(info[0])
skillList.append(int(info[1]))
numberList.append(int(info[2]))
numFile.close
print("Rank\t\tSkill\t\tNumber")
print(45*"=")
for i in range(len(rankList)):
print("%-10s\t%3i\t\t%3i" %(rankList[i], skillList[i], numberList[i]))
How do I add the deck of cards list?
How do I add the deck of cards in a list? This is how the list is supposed to look:
========================================
Level 3 Build Deck
========================================
['Admiral', 'General', 'Colonel', 'Colonel', 'Major', 'Major', 'Captain', 'Captain', 'Lieutenant', 'Lieutenant', 'Sergeant', 'Sergeant', 'Sergeant', 'Sergeant', 'Corporal', 'Corporal', 'Corporal', 'Corporal', 'Corporal', 'Corporal', 'Private', 'Private', 'Private', 'Private', 'Private', 'Private', 'Private', 'Private', 'Private', 'Private']