回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>所以,如果你输入</p>
<pre><code>Type: Item
Total: 1,2 or 3
Item Type: Head
</code></pre>
<p>它“应该”循环,从特定类型的选项列表中选择,然后选择更多,如果可以的话,并确保它们不是重复的。你知道吗</p>
<pre><code>import random
firstb = input('Type: ')
rarPropin = input('Total: ')
rarPropTotal = int(rarPropin)
first_random_item = input('Item Type: ')
item_slots = ['Head', 'Earring', 'Necklace']
HeadPropList = ['Stat1', 'Stat2', 'Stat3']
HeadWeight = [1, 0.5, 0.25]
EarPropList = ['Stat4', 'Stat5', 'Stat6']
EarWeight = [1, 0.5, 0.25]
NeckPropList = ['Stat7', 'Stat8', 'Stat9']
NeckWeight = [1, 0.5, 0.25]
ItemPropList = [HeadPropList, EarPropList, NeckPropList]
ItemWeightList = [HeadWeight, EarWeight, NeckWeight]
ItemProp = {Li: Prop for (Li, Prop) in zip(item_slots, ItemPropList)}
ItemWeight = {Li: Prop for (Li, Prop) in zip(item_slots, ItemWeightList)}
PropRoll = ItemProp[first_random_item]
Propstr = str(PropRoll)
PropWeight = ItemWeight[first_random_item]
Weightstr = str(PropWeight)
if firstb == "Item":
S = []
l = len(S)
while l < rarPropTotal:
c = random.choice([Propstr], [Weightstr])
S.append(c)
while S.contains(c):
c = random.choice(Propstr, Weightstr)
S.append(c)
print("Property List: " + S)
</code></pre>
<p>但我不断发现以下两个错误:</p>
<pre><code>Error 1: TypeError: choice() takes 2 positional arguments but 3 were given
Error 2: ValueError: The number of weights does not match the population
</code></pre>