Oct-30-2019, 03:32 AM
(This post was last modified: Oct-30-2019, 04:00 AM by newbieAuggie2019.)
(Oct-29-2019, 04:00 AM)christing Wrote: May i ask. what function i can use to make me confirm my string position number one number if i get 1, i will get ok else i will get fail.
Hi!
Maybe this can give you some ideas:
mystring = "11000000000000000000000000000000" for character in mystring: if character == '1': print(f"O.K., the character '{character}' in my string is '1'.") else: print(f"Fail, the character '{character}' in my string is not '1'.")and that produces the following output:
Output:O.K., the character '1' in my string is '1'.
O.K., the character '1' in my string is '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
Fail, the character '0' in my string is not '1'.
>>>
I hope it helps.All the best,
Hi again!
If you are looking for a certain position in the string, this may give you some ideas (although it's not very good code, but I think it's easier for newbies):
mystring = "abcdefghijk" for positions in range(len(mystring)): if mystring[positions] == 'g': print(f"O.K., the character '{mystring[positions]}' in my string is 'g'.") else: print(f"Fail, the character '{mystring[positions]}' in my string is not 'g'.")that produces the following output:
Output:Fail, the character 'a' in my string is not 'g'.
Fail, the character 'b' in my string is not 'g'.
Fail, the character 'c' in my string is not 'g'.
Fail, the character 'd' in my string is not 'g'.
Fail, the character 'e' in my string is not 'g'.
Fail, the character 'f' in my string is not 'g'.
O.K., the character 'g' in my string is 'g'.
Fail, the character 'h' in my string is not 'g'.
Fail, the character 'i' in my string is not 'g'.
Fail, the character 'j' in my string is not 'g'.
Fail, the character 'k' in my string is not 'g'.
>>>
So you can check a character in a certain position, for instance:Output:>>> mystring = "abcdefghijk"
>>> mystring[0]
'a'
>>> mystring[3]
'd'
>>> mystring[5]
'f'
>>> mystring[8]
'i'
>>> mystring[10]
'k'
>>>
I hope it helps.All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs