Python Forum
How to call the values at the end of a text string?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call the values at the end of a text string?
#1
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
Reply
#2
print(f"alpha {a}")
Or
print("alpha {0}".format(str(a)))
Or
print("alpha " + str(a))
Reply
#3
Almost arrived at the last solution
except i wrote it as
print ("alpha") + str(a) 
thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  Trying to compare string values in an if statement israelsattleen 1 519 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,120 Jul-07-2023, 05:44 PM
Last Post: flash77
  Getting rid of old string values Pedroski55 3 971 Oct-11-2022, 10:56 PM
Last Post: Pedroski55
  mutable values to string items? fozz 15 2,699 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,197 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Editing text between two string from different lines Paqqno 1 1,287 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  Extract a string between 2 words from a text file OscarBoots 2 1,827 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Replace String in multiple text-files [SOLVED] AlphaInc 5 7,962 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  fuzzywuzzy search string in text file marfer 9 4,432 Aug-03-2021, 02:41 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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