Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How can I find a string in sequence (with Booleans)?
#1
I receive a String. For example in here I have : Mystring= ‘alohrefllluqoo’ I am going to find the ‘hello’ in that string by using Booleans. Is it possible?

the final output would be 'YES', cause when we remove extra letter we can see the 'Hello' word in first string.

and if the sequence and the word can not be found, the output will be 'NO'
Quote
#2
Using booleans (True and False)? No, not possible. Using conditionals that evaluate to True or False (if mystring[index] == char:)? Possible. I would prefer the index method of sequences, or better yet regular expressions.

In any case, what have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
I have wrote it in this way. but some one told me that I can Use Boolean-without any further info and I am wonder how?!!

firststring = input() #ahhellllloou
to_find = "hello"

def check_string(firststring, to_find):
    c = 0
    for i in firststring:
        #print(i)
        if i == to_find[c]:
            c += 1
        if c == len(to_find):
        
            return "YES"
    return "NO"

print(check_string(firststring, to_find))
Quote
#4
As I said, python tags, not output tags.

If someone said you can do that using booleans, I don't know what they are talking about either. I would ask them to clarify what they mean.

Although, I would have the function return True and False rather than "YES" and "NO". Maybe that's what they were talking about. Then you can just use if check_string(text, to_find): rather than if check_string(text, to_find) == 'YES':.
go127a likes this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to Find & Count String Patterns Between two Markers in a HTML file ahmedwaqas92 3 220 Aug-19-2019, 10:12 AM
Last Post: ahmedwaqas92
  Find string and add character - newbi PyDK 1 212 May-15-2019, 01:22 PM
Last Post: ichabod801
  String Method 'find(...)'. ClassicalSoul 3 351 Feb-27-2019, 12:24 PM
Last Post: buran
  Find ? in string MuntyScruntfundle 5 432 Jan-17-2019, 08:11 PM
Last Post: buran
  Find closest string pattern jmair 9 580 Dec-12-2018, 09:17 PM
Last Post: jmair
  How to find previous string of a string Prince_Bhatia 1 596 Sep-26-2018, 02:31 PM
Last Post: gruntfutuk
  How Do I find Index of a character in string? ilcaa72 5 829 May-23-2018, 11:44 PM
Last Post: wavic
  Beginner Q: failure to find string in list Jenny 2 604 Mar-18-2018, 01:07 PM
Last Post: Jenny
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 998 Mar-03-2018, 05:23 PM
Last Post: Gribouillis
  find a character in a string in python3 tony1812 6 2,644 Sep-27-2017, 03:28 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)