Python Forum
Print variable without '' and spaces
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print variable without '' and spaces
#1
Hello all,
could you help me with below question:

x = int(input("Enter the number:"))
a = str(([random.choice("ABCD" for _ in range(x)]))
var1 = 'X'
var2 = 'Y'
var3 = 'Z'

print (a) - this function display e.g. ['T', 'C', 'A'] I need display like string ['TCA']

b = ""
for char in a:
if char == "X":
b.join(var1)
if char == "Y":
b.join(var2)
if char == "Z":
b.join(var3)
b = b.split()
print (b) - this function display correct e.g. ['YZX']
Yoriz write Jan-30-2023, 06:46 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
None of your code makes any sense. What are you trying to do? Are your trying to make a three-letter string?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with print variable in print.cell (fpdf) muconi 0 1,139 Dec-25-2022, 02:24 PM
Last Post: muconi
  Remove a space between a string and variable in print sie 5 2,914 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Can you print a string variable to printer hammer 2 2,787 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print variable between " paulo79 5 2,663 Mar-11-2022, 05:16 PM
Last Post: deanhystad
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 3,172 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov
  Print variable values from a list of variables xnightwingx 3 3,423 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Print part of a variable rs74 4 3,494 Jul-27-2020, 04:39 PM
Last Post: rs74
  How to print variable name? mayadob 11 10,579 Oct-21-2019, 01:34 AM
Last Post: ichabod801
  How do I print a returned variable calculated in another function? RedSkeleton007 3 4,429 Jul-10-2018, 12:10 PM
Last Post: buran
  Empty variable when using print before readline fstefanov 3 4,548 Oct-23-2017, 02:22 AM
Last Post: fstefanov

Forum Jump:

User Panel Messages

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