Imbadatcoding
Coder
This is an extract of my code that is causing problems. The overall code counts up the amount of time the user obtains an item (can be used for many games but im using 3, 4, 5 stars as generic example) However i added a simulation mode where the player can choose to get random items from the computer which isnt going well...
The output is:
Computer1 obtains... [3, 4]
Computer2 obtains... [3, 3]
Table of items obtained
Computer1 3 Stars obtained: 1
Computer1 4 Stars obtained: 1
Computer1 5 Stars obtained: 0
Computer2 3 Stars obtained: 1
Computer2 4 Stars obtained: 0
Computer2 5 Stars obtained: 0
The problem is that it only counts up the first number so whenever there is more than one 3 star etc it doesn't register it. I'm assuming I need to change the if statements? Sorry i'm not good at explaining the problem but i hope you can understand. The next step will be to to record all the data obtained and adding it to a cvs file which i'm also not sure how to do so if anyone knows how to do that, that'd be helpful. thank u!!
Code:
if opponentChoice == "c": #simulation
Com1 = "Computer1"
weighted_list1 = random.choices(com1List, weights=(10, 3, 1), k=maxplays)
print("Computer1 obtains...", weighted_list1)
Com2 = "Computer2"
weighted_list2 = random.choices(com2List, weights=(10, 3, 1), k=maxplays)
print("Computer2 obtains...", weighted_list2)
a = 3
b = 4
c = 5
if a in weighted_list1:
comthree = comthree + 1
if b in weighted_list1:
comfour = comfour + 1
if c in weighted_list1:
comfive = comfive + 1
if a in weighted_list2:
comthree2 = comthree2 + 1
if b in weighted_list2:
comfour2 = comfour2 + 1
if c in weighted_list2:
comfive2 = comfive2 + 1
print("Table of items obtained")
print(" ", Com1, "3 Stars obtained:", comthree)
print(" ", Com1, "4 Stars obtained:", comfour)
print(" ", Com1, "5 Stars obtained:", comfive)
print()
print(" ", Com2, "3 Stars obtained:", comthree2)
print(" ", Com2, "4 Stars obtained:", comfour2)
print(" ", Com2, "5 Stars obtained:", comfive2)
The output is:
Computer1 obtains... [3, 4]
Computer2 obtains... [3, 3]
Table of items obtained
Computer1 3 Stars obtained: 1
Computer1 4 Stars obtained: 1
Computer1 5 Stars obtained: 0
Computer2 3 Stars obtained: 1
Computer2 4 Stars obtained: 0
Computer2 5 Stars obtained: 0
The problem is that it only counts up the first number so whenever there is more than one 3 star etc it doesn't register it. I'm assuming I need to change the if statements? Sorry i'm not good at explaining the problem but i hope you can understand. The next step will be to to record all the data obtained and adding it to a cvs file which i'm also not sure how to do so if anyone knows how to do that, that'd be helpful. thank u!!