Python Forum
First time poster...need help with a snippet
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First time poster...need help with a snippet
#1
I'm having a problem with a snippet of code for a game I decided to make. All this code snippet does is on player death it iterates through the item list the player had and removes half of their items (rounded up) I'm a bit new to coding so if anyone has suggestions on how to clean this up I would also appreciate that as well. What I think the problem seems to be, is when the it flips the coin and they get to keep the items the counter doesn't go up and so when it reaches the end of the list of items it doesn't start over at 0 it just stops...if that makes any sense. Any help would be greatly appreciated!

import random

item_list = [
    'Heart of Gold', 'Rod of Ages', "Rabadon's Deathcap", 'Guardian Angel',
    'Bloodthirster', 'Ionic Spark', "Mejai's Soustealer"
    ]

number_of_items = len(item_list)

player_death = True

def on_death_items(item_list, number_of_items):

    items_to_destroy = (number_of_items/2)

    if isinstance(items_to_destroy, float):
        items_to_destroy += .5
    else:
        pass

    counter = 0

    while counter != items_to_destroy:
        for x in item_list:
            coin_flip = random.randint(0,1)
            if coin_flip == 0:
                item_list.remove(x)
                counter += 1
            else:
                counter += 0
            
    return item_list

print(item_list)
while player_death:
    on_death_items(item_list, number_of_items)
    player_death = False
print(item_list)
Reply


Messages In This Thread
First time poster...need help with a snippet - by globalcooldown - Jul-24-2019, 04:09 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020