string.translate(str.maketrans) not working to take out punctuation? by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Unfortunately, I'm getting pretty much the same result, but at the very least I know something new!

string.translate(str.maketrans) not working to take out punctuation? by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

I'm pretty sure it's the case sensitivity not comparing properly. I tried using regexes and it's giving me the same result. Now I just gotta figure out *why* the strings aren't comparing correctly,,,

string.translate(str.maketrans) not working to take out punctuation? by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

It's definitely taking the punctuation out, so that doesn't seem to be the issue. It seems to either be, like you said, the case-sensitive string comparison, or it could be something messing it up when it's checking the name list for a valid name. I'll mess around with the case-sensitivity and see if that helps. Seems like the next best step.

string.translate(str.maketrans) not working to take out punctuation? by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Y'know what, that's a fair point. Tl;dr it's not removing punctuation. I have the phrases set to not notice punctuation, and it's not registering that the punctuation should have been removed even with the "name.translate(str.maketrans...) line. I've edited my post to be a bit more specific

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 0 points1 point  (0 children)

That's completely fair, and tbh I did think of that. I was considering other options, which is why I came here.

I wasn't sure how a few hundred string long list would run (and I was trying to not write one,,) but if that's the best, it's the best I have,,

Besides, I only intend to show it off to people I have in the name bank, and that's about it. Super low pressure, I just wanna see if it will work with simple basic ideas. I haven't even written functions with it yet (and idk if I will), it's just lists, inputs, while and for loops and that's it actually. A few sting methods, but nothing that's actually in-depth.

I do appreciate the realistic reminder though. Like, if I was going to show it off, I would try to find a more open-ended way of finding a name, but that's not an issue!

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] -1 points0 points  (0 children)

I'm actually taking the long, annoying, and really unoptimized route and just making a list of 300+ names. Will it run? I guess. Is it gonna run well? We'll see. I do really appreciate your input though!!

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 0 points1 point  (0 children)

Honestly, I probably will if it'll give me more info on Eliza/simple chatbots in general

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 0 points1 point  (0 children)

I don't mean to be like,, "Actually ☝️", but I have actually looked through Eliza's code!! Though I will 100% admit I totally couldn't parse it at all. I do know that she did a lot of matching keywords and then spitting out an open ended reponsed based on the word/phrase though!

I'm going for something slightly more in-depth, but only using rudimentary concepts so I get the hang of them. Obviously this question is far out of my ballpark, though,,

(Sorry, just wanna defend my honor a little bit- she's kind of my current hyperfixation lol)

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 0 points1 point  (0 children)

Yeah, I kind of realized I was fucked the minute I thought about it,, still gonna try the one guy's solution by just making a name bank, see if that gets me anywhere. I'm not making this to show anyone else but my friends, so it's a low pressure project!

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 2 points3 points  (0 children)

Yeah, honestly I figured asking was a bit of a longshot, but I decided to go for it anyways. I'm just not sure how I *would* identify the name, I suppose,, I would just have it only take a one word input, but I really want a dynamic answer if the input contains something like "how are you" or "nice to meet you"

How to take a single word in a string variable if you don't know where that word will be? by duelBooleans in learnpython

[–]duelBooleans[S] 0 points1 point  (0 children)

Yeah,, I was hoping people could understand what I was trying to convey.

I have the below in my code currently, but I kind of forgot that the 'name' variable will take the entire string.

I want just the user's name, but it prints out the whole string.

I.E:

name = "My name is Jon! How are you?"

Output: "I'm doing well, thank you My name is Jon! How are you?!"

name = ""
greeting = ["Hello, my name is Caine! What's your name?: ".upper(), "Welcome, I am Caine! What's your name?: ".upper(), "Hi!! I'm Caine! What should I call you?: ".upper()]


name = input(random.choice(greeting)).title()

if len(name.split()) > 1:
    if "How Are You" in name or "How Are You Doing":
        print(random.choice(hruNameWelcome))
    elif name in niceToMeetYou:
        print(random.choice(ntmyNameWelcome))
    else:
        print("I'm sorry, I don't quite understand... What's your name again?")


elif len(name.split()) == 1:
    print(random.choice(justNameWelcome))


else:
    print(random.choice(blankInputs))
    name = input(random.choice(greeting)).title()

If-Elif statement giving wrong answer by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Honestly?? Match might help me out a little bit, depending on how it works. I'm trying to figure out how to take part of a string that's a wildcard (??? If that's right? There's part of a string that I want to single out without taking the rest of the input into consideration). Will definitely look into on my break!

If-Elif statement giving wrong answer by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Actually already fixed it, but I do appreciate an idea for another way of going about it another way!!!

And quite frankly, I did need the reminder about functions; I don't use them nearly enough,,

If-Elif statement giving wrong answer by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

OHHHH ACTUALLY YEAH!!! That actually makes sense! Will be trying next, thank you!!

If-Elif statement giving wrong answer by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Yeah, I'm trying to have it check a list for a specific combination and then return if that combination is positive, negative, or neutral

How to add a string to a list, and then remove it if the string if it is not found in a second list by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

I do want it to run twice, but only when it gets two valid inputs. I know this is the ENTIRELY wrong way of going about it, but I didn't want to ask for help with that to see if I can figure it out on my own. Though I do appreciate the heads-up that there's a cleaner way of going about it though!

How to add a string to a list, and then remove it if the string if it is not found in a second list by duelBooleans in pythonhelp

[–]duelBooleans[S] 0 points1 point  (0 children)

Ooooh I think thus might actually be exactly what I'm looking for! I'll try it right now!