3

I'm trying to complete my code with a main function that should be able to produce an output that looks like this:

consecutive('qqrrb12ss') = True
one_digit('qqrrb12ss') = True
not_nums('qqrrb12ss') = True
length('qqrrb12ss') =True
string_req('qqrrb12ss', old_strings) = True

consecutive('y123bz') = True
one_digit('y123bz') = True
not_nums('y123bz') = True
length('y123bz') = False
string_req('y123bz', old_strings) = False

consecutive('1222345') = False
one_digit('1222345') = True
not_nums('1222345') = False
length('1222345') = False
string_req('1222345', old_strings) = False

consecutive('top89hat') = True
one_digit('top89hat') = True
not_nums('top89hat') = True
length('top89hat') = True
string_req('top89hat', old_strings) = False

My helper functions should be able to do this:

  • consecutive: if string has no substring of 3 of the same characters consecutively, returns True
  • one_digit: if string has at least 1 digit, returns True
  • not_nums: if first and last chars are letters, returns True
  • length: string length must be between 8 and 16 for it to return True
  • string_req: it's basically all of the other helper functions in one, in addition to ensuring that the new string hasn't been inputted previously

All my helper functions (i.e 'consecutive', 'one_digit', etc.) work perfectly on its own. But I'm having a hard time putting it all together to create this output. Here is what I have so far for the main function:

# Strings used to test function
old_strings = [ 'xyz556677abc', 'top89hat' ]
strings = [ 'qqrrb12ss', 'y123bz','1222345', 'top89hat' ]

def function():
    s = strings
    L = old_strings

    for # I do know I have to use a loop.. But how exactly should I use it?:
        print("consecutive", s, "=", consecutive) # should return True or False
        print("one_digit", s, "=", one_digit)
        print("not_nums", s, "=", not_nums)
        print("length", s, "=", length)
        print("string_req", s, L, "=", string_req)

Additionally, this is the output I'm getting:

consecutive['aabb12cc', 'a123b', 'a1234546b', 'a1234546b0', 'abcdef1pqrstuvwx', 'abcdef1pqrstuvw', '1222345', 'bat23man']  --> <function consecutive at 0x101d9a950>
one_digit ['aabb12cc', 'a123b', 'a1234546b', 'a1234546b0', 'abcdef1pqrstuvwx', 'abcdef1pqrstuvw', '1222345', 'bat23man']  --> <function one_digit at 0x101d9a9d8>
not_nums ['aabb12cc', 'a123b', 'a1234546b', 'a1234546b0', 'abcdef1pqrstuvwx', 'abcdef1pqrstuvw', '1222345', 'bat23man']  --> <function not_nums at 0x101d9a8c8>
length ['aabb12cc', 'a123b', 'a1234546b', 'a1234546b0', 'abcdef1pqrstuvwx', 'abcdef1pqrstuvw', '1222345', 'bat23man']  --> <function length at 0x101d9a730>
string_req ['aabb12cc', 'a123b', 'a1234546b', 'a1234546b0', 'abcdef1pqrstuvwx', 'abcdef1pqrstuvw', '1222345', 'bat23man'] ['abc112233xyz', 'bat23man']  --> <function string_req at 0x101d9a6a8>
1
  • You need to call your functions and pass in the string values. Commented May 9, 2018 at 23:31

1 Answer 1

2

You can use it in this way.

for old_s in old_string:
    print('consecutive {s} = {ans}'.format(s = old_s, ans = consecutive(old_s)))
    print('one_digit {s} = {ans}'.format(s = old_s, ans = one_digit(old_s)))
    print('not_nums {s} = {ans}'.format(s = old_s, ans = not_nums(old_s)))
    print('length {s} = {ans}'.format(s = old_s, ans = length(old_s)))
for new_s in strings:
    print('string_req of {s} and {L} = {ans}'.format(
           s = new_s, L = old_strings, ans = string_req(new_s, old_strings)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.