-2

I want to test whether the letter a appears more than once in my string employee_name.

I have tried this code :

if 2*"a" in employee_name:
    return a

This did not work. What am I doing wrong?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • What do you mean by that? Do you need to be check for more than one occurrence of a, is there some pattern to how they could appear? Depending on that answer, regex might be the way to go. – InsertCheesyLine Mar 28 '21 at 06:49
  • 2
    Well, what did you get when you checked the value of `2*"a"`? Is that exactly the condition you need? – Prune Mar 28 '21 at 06:49
  • 1
    Do you know how to check how many times `"a"` appears? If so, can you think of a way to use that information to solve the problem? If not, did you try reviewing your course notes and the documentation? – Karl Knechtel Mar 28 '21 at 06:50
  • I edited the question to ask a clear question (please see [ask] and [How do I ask and answer homework questions?](https://meta.stackoverflow.com/q/334822)) and to remove confusing context (why are you talking about a "password generator" if the variable you are checking is called `employee_name`) and [fluff](https://meta.stackoverflow.com/questions/260776/should-i-remove-fluff-when-editing-questions) (we [don't care about the urgency of your task](https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest)). – Karl Knechtel Mar 28 '21 at 06:54

1 Answers1

1
if employee_name.count("a") >= 2:

Any time you need to know a bit more about a straightforward access or check, just repeat the tutorial on that topic. I often find things I'd forgotten.

Prune
  • 76,765
  • 14
  • 60
  • 81