Python Forum
How to call the values at the end of a text string? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to call the values at the end of a text string? (/thread-11310.html)



How to call the values at the end of a text string? - Dieselkaine - Jul-02-2018

Total beginner.
Cant get the last line to work as intended.
want it to print the text and the value
something like this
alpha 5

Also i don't understand exactly how the alpha and bravo blocks work
stole the code from another post
just that they seem to hold the values and i'm able to call them elsewhere
so a quick explanation would be appreciated.

thanks in advance

### fighter stats ###
def alpha(*values):
    alpha.values = values or alpha.values
    return alpha.values
alpha.values =()

def bravo(*values):
    bravo.values = values or bravo.values
    return bravo.values
bravo.values =()

alpha(5, 3, 2)
a, b, c = alpha()

bravo(2, 5, 3)
d, e, f = bravo()

def intro():
    fighter = ""
    while fighter != 1 and fighter != 2:
        print ("Choose a fighter 1)Alpha 2)Bravo")
        print (a, b, c, d, e, f)
        fighter = input()
        print (a + e)
        print (a + 1)
        print (e + 2)
        print ("alpha " ) + (a)
        ### tried several different ways of writing this last line ###
        ### can't get it to work ###
    
    return fighter



RE: How to call the values at the end of a text string? - gontajones - Jul-02-2018

print(f"alpha {a}")
Or
print("alpha {0}".format(str(a)))
Or
print("alpha " + str(a))



RE: How to call the values at the end of a text string? - Dieselkaine - Jul-02-2018

Almost arrived at the last solution
except i wrote it as
print ("alpha") + str(a) 
thank you