#Let's Look at Unpacking a List
holy_grail_items = [ ["Holy Hand Grenade of Antioch", "A sacred explosive that obliterates almost anything when counted to three.", 100, 80],
["Excalibur", "The legendary sword of King Arthur, forged for righteous combat.", 75, 50],
["Rabbit of Caerbannog", "A small white rabbit with an extremely violent disposition.", 90, 60],
["Knight Who Says Ni Shrub","A heavy decorative shrub wielded with unreasonable menace.", 30, 10],
["Coconut Horse","A pair of coconuts used to simulate a galloping steed.", 15, 5],
["Black Knight Sword Stump", "A sword still swung effectively despite the loss of several limbs.", 40, 20],
["Sir Lancelot's Charging Lance", "A lance used at full sprint with zero regard for personal safety.", 65, 35],
["French Taunter's Insults", "A barrage of devastating mockery hurled from castle walls.", 25, 10]]
def print_items(): #Unpacking A List topbottom = "-"*85 head_num = "ITEM ID".center(10) head_iname = "ITEM NAME".center(40) head_min = "MIN DAMAGE".center(12) head_max = "MAX DAMAGE".center(12) head_div = " | ".center(3) print(topbottom) print(f"{head_num}{head_div}{head_iname}{head_div}{head_min}{head_div}{head_max}") print(topbottom)
itemnum = 1 for iname, idesc, imax, imin in holy_grail_items: thenum = (str(itemnum) + " ").rjust(10) iname = iname.center(40) imax = str(imax).center(12) imin = str(imin).center(12) print(f"{thenum}{head_div}{iname}{head_div}{imax}{head_div}{imax}") itemnum += 1
while True: try: print_items() print() themax = len(holy_grail_items) choice = int(input(f"Please Make a Selection (1-{themax}) or 99 To Exit: ")) if(1<=choice<=themax): iname, idesc, imin, imax = holy_grail_items[choice-1] print(f"Item Selected: {iname}") print(f" ~{idesc}") print() input("Press ENTER to Continue...") elif(choice == 99): print("Exiting Program...") break else: raise Exception(f"You Must Select between 1 and {themax}!!") except ValueError: print("That is not a valid Selection. Please Try Again") except Exception as e: print(e)