コード例 #1
0
ファイル: main.py プロジェクト: wincjva/python-course-strings
def num_joey_facts():
    koala_facts_list = []
    joey_facts = []
    fact_to_be_added = random_koala_fact()
    while koala_facts_list.count(fact_to_be_added) < 10:

        koala_facts_list.append(fact_to_be_added)
        if fact_to_be_added not in joey_facts and "joey" in fact_to_be_added:
            joey_facts.append(fact_to_be_added)
        fact_to_be_added = random_koala_fact()
    else:
        return len(joey_facts)
コード例 #2
0
ファイル: main.py プロジェクト: wincjva/python-course-strings
def koala_weight():
    random_fact = random_koala_fact()
    count = 0
    while count < 1000:
        random_fact = random_koala_fact()
        if "kg " in random_fact or "kg." in random_fact:
            break
        count += 1
    else:
        print("while loop ended with:", random_fact)
    weight_fact = random_fact.split("kg")
    weight = weight_fact[0].split()
    return int(weight[-1])
コード例 #3
0
def num_joey_facts():
    joey_facts_found = []
    joey_facts_seen_enough = []
    i = 1
    go_on = True
    while go_on == True:
        if i > 1000:
            go_on = False
            break
        generated_fact = str(random_koala_fact())
        if not 'joey' in generated_fact:
            i += 1
            continue
        elif generated_fact in joey_facts_seen_enough:
            i = i + 1
            continue
        else:
            update_joey_facts_found(generated_fact, joey_facts_found)
            if enough_unique_joey_facts(joey_facts_found,
                                        joey_facts_seen_enough) == True:
                go_on = False
                break
            else:
                i += 1
                continue
    # print('joey_facts_found: ', joey_facts_found)
    result = len(joey_facts_found)
    return result
コード例 #4
0
def num_joey_facts():
    first_fact = random_koala_fact()
    times_seen_first_fact = 0
    num_joey_facts = 0
    # Using a set instead of a list for unique_facts would be better if you are
    # familiar with it.
    unique_facts = []

    while times_seen_first_fact < 10:
        fact = random_koala_fact()
        if fact == first_fact:
            times_seen_first_fact += 1
        if fact not in unique_facts:
            unique_facts.append(fact)
            if "joey" in fact.lower():
                num_joey_facts += 1
    return num_joey_facts
コード例 #5
0
ファイル: main.py プロジェクト: keesvanoss/Python
def koala_weight():
  while True:                                 # Endless loop
    fact = random_koala_fact()                # Get fact
    if ('weigh' in fact.lower()) and \
       ('kg' in fact.lower()):                # Check if 'weigh' ad 'kg' in fact 
      ptr1 = fact.lower().find('kg')          # Get index to 'kg'
      ptr2 = ptr1                             # Set start index number
      while fact[ptr2-1] != ' ':              # Point back until space
        ptr2 -= 1
      return int(fact[ptr2:ptr1])             # Return weight in kg as integer
コード例 #6
0
ファイル: main.py プロジェクト: wincjva/python-course-strings
def unique_koala_facts(count):
    koala_facts_list = []
    attempts = 0

    while (len(koala_facts_list) < count) and (attempts < 100):
        fact_to_be_added = random_koala_fact()
        if fact_to_be_added not in koala_facts_list:
            koala_facts_list.append(fact_to_be_added)
        else:
            attempts += 1
    return koala_facts_list
コード例 #7
0
ファイル: main.py プロジェクト: Ruben80/Winc-Academy
def unique_koala_facts(num_requested):
    loops, max_loops = 0, 1000
    facts = []
    while len(facts) < num_requested:
        fact = random_koala_fact()
        if fact not in facts:
            facts.append(fact)
        if loops > max_loops:
            break
        loops += 1
    return facts
コード例 #8
0
ファイル: main.py プロジェクト: keesvanoss/Python
def num_joey_facts():
  facts_list = []                             # Unique facts list
  fact_counters = [0] * 10                    # Counters how many times fact is read
  
  while True:                                 # Endless loop
    fact = random_koala_fact()                # Get random fact
    if 'joey' in fact.lower():                # Check if 'joey in fact
      if fact not in facts_list:              # If so, check if fact in unique list
        facts_list.append(fact)               # If not, append to unique list
      ptr = facts_list.index(fact)            # Get index to fact
      fact_counters[ptr] += 1                 # Increment facts counter
      if 10 in fact_counters:                 # If a fact repeated 10 times
        return len(facts_list)                # Exit and return number of unique facts with 'joey'
コード例 #9
0
ファイル: main.py プロジェクト: Jsloot1986/Python_wincpy
def unique_koala_facts(target: int) -> list:
     count = 0
     fact_list = []
     while count < 50:
         if len(fact_list) == target:
             break
         else:
             fact = random_koala_fact()
             if fact not in fact_list:
                 fact_list.append(fact)
             else:
                 count = + 1
     return fact_list
コード例 #10
0
ファイル: main.py プロジェクト: Jsloot1986/Python_wincpy
def koala_weight(target: int) -> int:
    weight_koala = []
    count = 0
    while count < 30:
        if len(weight_koala) == target:
            break
        else:
            fact = random_koala_fact()
            if "14kg" in fact:
                weight_koala.append(fact)
            else:
                count += 1
    return str(weight_koala).find("kg")
コード例 #11
0
ファイル: main.py プロジェクト: Jsloot1986/Python_wincpy
def num_joey_facts(target: int) -> list:
    count = 0
    joey_facts = set()
    while count < 20:
        if len(joey_facts) == target:
            break
        else:
            fact = random_koala_fact()
            if "joey" in fact:
                joey_facts.update([fact])
            else:
                count =+ 1
    return joey_facts
コード例 #12
0
def koala_weight():

    bool = 0

    while bool == 0:

        fact = random_koala_fact()

        if 'weigh' and 'kg' in fact:
            weight = fact[fact.find('kg') - 2:fact.find('kg')]

            bool = 1

    return weight
コード例 #13
0
def unique_koala_facts(nr_of_koala_facts):

    unique_facts = []

    while len(unique_facts) < nr_of_koala_facts:

        x = random_koala_fact()

        if x not in unique_facts:
            unique_facts.append(x)

        if len(unique_facts) == 29:
            break

    return unique_facts
コード例 #14
0
def koala_weight():
    i = 1
    go_on = True
    while go_on == True:
        if i > 300:
            go_on = False
        else:
            weight_fact = str(random_koala_fact())
            if 'weigh' and 'kg' in weight_fact:
                go_on = False
            else:
                i += 1
                continue
    kg_index = weight_fact.find('kg')
    weight_index = weight_fact.rfind(' ', 0, kg_index)
    weight = int(weight_fact[weight_index:kg_index])
    return weight
コード例 #15
0
def num_joey_facts():

    max_nr = 10
    facts = []
    nr_joeys = 0
    nr_of_reps = 0

    while nr_of_reps < max_nr:
        x = random_koala_fact()
        if x in facts:
            nr_of_reps += 1
        facts.append(x)

    for fact in facts:
        if 'joey' in fact:
            nr_joeys += 1

    return nr_joeys
コード例 #16
0
ファイル: main.py プロジェクト: keesvanoss/Python
def unique_koala_facts(nr_of_facts):

  facts_list = []                             # Unique facts list
  old_nr = 255                                # Remember nr of facts of facts for iteration check
  iterations = 200                            # Stop after repeating 200 times the same nr of facts
  
  while nr_of_facts > 0:
    fact = random_koala_fact()                # Get random fact
    if fact not in facts_list:                # Check if fact in unique list
      facts_list.append(fact)                 # If not, append to unique list
      nr_of_facts -= 1                        # Decrement nr of facts
    if old_nr == nr_of_facts:                 # Check for the same nr of facts
      iterations -= 1                         # Check for 200 times
      if iterations == 0: nr_of_facts = 0     # After 200 times, stop reading facts -> exit
    else:                                     # If new fact
      old_nr = nr_of_facts                    # Save nr of facts
      iterations = 200                        # Reset iterations
  return facts_list                           # Return unique list
コード例 #17
0
def unique_koala_facts(number):
    unique_facts = []
    i = 1
    go_on = True
    while go_on == True:
        if i > 300:
            go_on = False
        if len(unique_facts) == number:
            break
        else:
            new_fact = str(random_koala_fact())
            if new_fact in unique_facts:
                i += 1
                continue
            else:
                unique_facts.append(new_fact)
                i += 1
    return unique_facts
コード例 #18
0
ファイル: main.py プロジェクト: WincAcademy/wincpy
from helpers import random_koala_fact

__winc_id__ = "c0dc6e00dfac46aab88296601c32669f"
__human_name__ = "while"

# This block is only executed if this script is run directly (python main.py)
# It is not run if you import this file as a module.
if __name__ == "__main__":
    print(random_koala_fact())
コード例 #19
0
ファイル: main.py プロジェクト: Ruben80/Winc-Academy
def koala_weight():
    fact = random_koala_fact()
    while 'kg' not in fact.lower():
        fact = random_koala_fact()
    return int(fact.split('kg')[0].split(' ')[-1])
コード例 #20
0
def koala_weight():
    fact = random_koala_fact()
    while "kg" not in fact.lower():
        fact = random_koala_fact()
    return int(fact.split("kg")[0].split(" ")[-1])