Python Forum
String being broken up into single characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String being broken up into single characters
#2
I think the problem is that the contents of the Color_Names variable is inconsistent at different parts of the file. If Color_Names' value is the list ['Red', 'Green', 'Blue', 'Yellow'], then calling random.choice(Color_Names) returns one of these colors, such as 'Blue'. But at the end of askcolornames(), you return Color_Names[0], which would be 'Red' in our case. If Color_Names is the single word 'Red', the call random.choice(Color_Names) will return a random letter from the word 'Red'. This random letter could be 'e'. So you need to be consistent in the use of this variable, make sure that Color_Names is always a list of strings and not a single string.
Reply


Messages In This Thread
RE: String being broken up into single characters - by Gribouillis - Dec-31-2018, 07:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  doing string split with 2 or more split characters Skaperen 22 2,321 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,430 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  Need help on how to include single quotes on data of variable string hani_hms 5 1,890 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python sql query single quote in a string mg24 1 996 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  Why is copying and pasting a block now broken? WagmoreBarkless 2 1,333 May-05-2022, 05:01 AM
Last Post: WagmoreBarkless
  Why is copying and pasting a block now broken? WagmoreBarkless 1 1,198 May-04-2022, 11:40 PM
Last Post: Larz60+
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,143 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  BrokenPipeError: [Errno 32] Broken pipe throwaway34 6 8,946 May-06-2021, 05:39 AM
Last Post: throwaway34
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,288 Apr-11-2021, 11:03 PM
Last Post: lastyle
  Extract continuous numeric characters from a string in Python Robotguy 2 2,583 Jan-16-2021, 12:44 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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