Python Forum
Locate user input in a string.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Locate user input in a string.
#1
New to Python, new to programming, sort of.. I love to play classic CRPG's, however instead of pulling out the graph paper to map out the dungeons as I play I decided to write a program that essentially allows me the joy of manually mapping out a dungeon, but using a digital map instead. I have no idea what I'm doing and I'm learning as go.

I'm supplying a prompt '(0)>' from which I want to collect user input using:

Con_Command = input(Con_Sole)
Am I adding 'Con_sole' '(0)>' to the users input? I think it is, so I am using this line:

Con_Command = Con_Command[5]
To try and find the first letter of the users input which currently is all I need to know, at least for now. However I'm getting an 'string index out of range error' so I must not be looking in the place place, or the input is not a string, because the if statements never run; hence why I added this line. If I try and print 'Con_Command' I get a memory address so, I'm lost.

#Console
Cursor_Position=[0,0]
Con_Sole = '(0)> '
Con_Command = ''

#Dungeon_Entrances

Dungeon_Entrances=['...you feel something crawling across your feet.',
    '...you get the sense of being watched from somewhere in the darkness just ahead.',
    'You hear a odd scream coming from deeper inside the dungeon',
    'What was that sound? The rattling of bones underfoot me thinks.',
    'Have a coin for the ferryman? You\'re going to be crossing the river styx quite often.']

print(" Welcome to the ye old CRPG Dungeon Mapper. If this is your first\n time here you can read the [M]anual"
" (\'crpgdm manual\'). You can\n also start a \'new\' map, \'load\' a previously explored area, or\n sit here and "
"\'enjoy\' the darkness.\n\n")

print (random.choice(Dungeon_Entrances))
print('\n\n')
Con_Command = input(Con_Sole)
Con_Command = Con_Command[5]


if (Con_Command) == 'new':
    if (Con_Command) == 'n':
        print('new dungeon routine runs here')
if (Con_Command) == 'load':
    if (Con_Command) == 'l':
        print('load routine runs here')
if (Con_Command) == 'enjoy':
    if (Con_Command) == 'darkness':
        print('easter egg routine runs here')
    else:
        print('You\'ll have to be more specific. Type 'Manual' for help or \'crpgdm manual\' on the console.')
Reply
#2
What is the output if you print Con_Command?
Reply
#3
A moment ago I swear it printed out a memory address, now ,however, it prints the user input as intended without the prompt included. So if I type 'new' Con_Command is 'new'. However the results of the 'if' statements never get's printed. So I assume it's never run.
Reply
#4
You need to remove line 21 with the [5]. Also note that line 32 is unreachable.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using string input for boolean tronic72 3 635 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 990 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
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
  restrict user input to numerical values MCL169 2 869 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,026 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,027 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,837 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,826 May-10-2022, 02:44 AM
Last Post: alisha17

Forum Jump:

User Panel Messages

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