Ask coding questions

← Back to all posts
Print Variable name as well as value in Python
devbois (3)

this is the code I have made with the team i am in:

from colorama import Fore, Back, Style
  
import os
from time import sleep 
#variables area
  #attack/damage values
b1ATK = 2
b2ATK = 20
b3ATK  = 40
b4ATK = 80
  # $$$ values
b1PRI = 10
b2PRI = 100
b3PRI = 200
b4PRI = 400
 #Shield defence values. Have not worked on yet
a1 = 20
a2 = 30
a3 = 50
  #weapon lists with ['Price', 'attack']
b1 = [b1PRI, b1ATK]
b2 = [b2PRI, b2ATK]
b3 = [b3PRI, b3ATK]
b4 = [b4PRI, b4ATK]
 #Swords list
swords = [b1, b2, b3, b4]
cash = 150 # cash -_-
myItems = [cash]#items
        

'''FUNCTIONS AREA
TO BE USED IN IF STATEMENT LATER
'''

def clear():
  os.system("clear")
  
clear()

def View_profile():
    clear()
    sleep(2)
    main_game()
    
   
def View_shop():
    clear()
    sleep(2)
    main_game()

def adventure():
    clear()
    sleep(2)
    main_game()

def training():
    clear()
    sleep(2)
    main_game()
    
   
def quest():
    clear()
    sleep(2)
    main_game()

def dungeon():
    clear()
    sleep(2)
    main_game()

def buy_items():
    clear()
    a  = 'Your cash is ' 
    print(a+str(cash))
   
    b = input(Fore.RED + 'You can buy the following things:\nBlade Items:\n b1)Wooden rapier: $10\n b2)SteelClaymore: $100\n b3)Endoplasmic Blade: $200\n b4)Neutrino Longblade: $400\nWhat would you like to buy? Type the code, for example,  b1.\n Enter Here:')
        
        
    
    if b == 'b1':
        if cash > b1PRI:
                myItems.append(swords[b1ATK])
                print('You now have a Wooden Rapier(Attack 2).')
        elif cash < b1PRI:
                        print('Your cash is insufficient to buy the Wooden Rapier')
                        main_game()
                        
    elif b == 'b2':
        if cash > b2PRI:
                myItems.append(swords[b2ATK])
                print('You now have a Steel Claymore (Attack 5).')
        elif cash < b2PRI:
                print('Your cash is insufficient to buy the Steel Claymore')
                main_game()
         
                        
    elif b == 'b3':
        if cash > b3PRI:
                myItems.append(swords[b3ATK])
                print('You now have a Endoplasmic Blade (Attack 10).')
        elif cash < b3PRI:
                print('Your cash is insufficient to buy the Endoplasmic Blade')
                sleep(2)
                main_game()
    elif b ==  'b4':

        if cash > b4PRI:
                myItems.append(swords[b4ATK])
                print('You now have a Neutrino Longblade (Attack 20).')
        elif cash < b2PRI:
                print('Your cash is insufficient to buy the Neutrino Longblade')
                sleep(2)
                main_game()
    sleep(2)
    main_game()
  
def sell_items():
  clear()
  sleep(2)
  main_game()

def my_items():
  clear()
  print('cash =  ')
  sleep(2)
  main_game()

#main game stuff
def main_game():
  clear()
  print("1) View Profile")
  print("2) View Shop")
  print("3) adventure")
  print("4) training")
  print("5) quest")
  print("6) dungeon")
  print("7) Buy items")
  print("8) sell items")
  print("9) View MyItems")
  current_action = input("Type the number of the action you would like to complete: ")
  if current_action == "1":
    View_profile()
  elif current_action == "2":
    View_shop()
  elif current_action == "3":
    adventure()
  elif current_action == "4":
    training()
  elif current_action == "5":
    quest()
  elif current_action == "6":
    dungeon()
  elif current_action == "7":
    buy_items()
  elif current_action == "8":
    sell_items()
  elif current_action == "9":
    print('cash = ', myItems)
    if b1 in myItems:
            print('cash = ', '\nWooden Rapier = 2 Damage')
    elif b2 in myItems:
            print('cash = ', str(cash), '\nSteel Claymore =', str(b2ATK), 'Damage')
    elif b3 in myItems:
            print('cash = ', str(cash), '\nEndoplasmic Blade =', str(b3ATK), 'Damage')
    elif b4 in myItems:
            print('cash = ', str(cash), '\nNeutrino Longblade =', str(b4ATK), 'Damage')
    elif b1 and b2 in myItems:
            print('cash = ', str(cash), '\Wooden Rapier =', str(b1ATK), 'Damage', '\nSteel Claymore =', str(b2ATK), 'Damage')
    elif b1 and b3 in myItems:
            print('cash = ', str(cash), '\Wooden Rapier =', str(b1ATK), 'Damage', '\nEndoplasmic Blade =', str(b3ATK), 'Damage')
    elif b1 and b4 in myItems:
            print('cash = ', str(cash), '\Wooden Rapier =', str(b1ATK), 'Damage', '\Neutrino Longsword =', str(b4ATK), 'Damage')
    
    

         
  else:
    print("Your action was void. Please type a valid action.")
    sleep(1.5)
    main_game()
main_game()```


The part with an if statement near the bottom is trying to find all the combinations of swords that you can have, just to print the name of the variable as well as the value. This is tedious, and I may be dead before we can finish this. PLease help, otherwise we will be coding in our coffins.
Comments
hotnewtop
Bookie0 (6298)

Can you send your repl? It'll be easier to help you! :)

Also you can try to check this StackOverflow page out.

Good luck! :D