Python Forum
user input to select and print data from another class python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
user input to select and print data from another class python
#1
This is a snippet of my playercharacter class, specifically the inventory which later calls Weapon which is another class with a list of weapons and individual stats. I am attempting to have user input select one of the weapons from the inventory specifically, then print out the details of the weapon, but am having difficulties coming up with the logic for it. Can anyone assist me in doing so?

def getinventory(self): 
    for object in self.inventory:
        print object.getname()

        choice = raw_input("""Do you wish to look at any of the items?
""")
        if choice == 'yes' or choice == 'y':
            choice = raw_input("""Which item?
""")
            if choice == object.name in self.inventory:
                object.__str__(choice)
Reply


Messages In This Thread
user input to select and print data from another class python - by TyTheChosenOne - Aug-30-2018, 04:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,149 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  Help with to check an Input list data with a data read from an external source sacharyya 3 506 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  manually input data jpatierno 0 372 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Input network device connection info from data file edroche3rd 6 1,159 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,137 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,118 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  print(data) is suddenly invalid syntax db042190 6 1,273 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  restrict user input to numerical values MCL169 2 983 Apr-08-2023, 05:40 PM
Last Post: MCL169
  class Update input (Gpio pin raspberry pi) caslor 2 858 Jan-30-2023, 08:05 PM
Last Post: caslor
  user input values into list of lists tauros73 3 1,113 Dec-29-2022, 05:54 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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