コード例 #1
0
ファイル: ex7.py プロジェクト: dogOfRiddles/pythonAcademy
import sys
import dogRandom

listLength = 12
evens = []

if len(sys.argv) == 1:
    print('Consider using the command line argument \'python3 ex7.py <listLength>\'')
    print('defaulting to "12"')

if len(sys.argv) == 2:
        print('Received submission: ',sys.argv[1])
        listLength = int(sys.argv[1])

randomList = dogRandom.getRandomList(listLength,0,100)

for index,element in enumerate(randomList):
    if int(element) % 2 == 0:
        evens.append(element)
        print(element,'found at index',index,'is submitted to new index:',len(evens)-1)
    else:
        print(element,'found at index',index,'is rejected for oddness.')
コード例 #2
0
import dogUtil
import dogRandom

print('We\'ll pull random numbers to be stripped of duplicates')
unsortedList = dogRandom.getRandomList(100, 0, 20)

dogUtil.walkList((dogUtil.removeDuplicates(unsortedList)))
コード例 #3
0
ファイル: ex10.py プロジェクト: dogOfRiddles/pythonAcademy
listToBeTested = []
listOfChosenOnes = []

if len(sys.argv) == 1:
    print('Consider using the command line argument \'python3 <script> <argument>\'')
    #print('Defaulting to "default value"')

if len(sys.argv) == 2:
    print('Received submission: ',sys.argv[1])
    try:
        argVariable = 1
        listToBeTested = sys.argv[1].split(",")
    except:
        print('Invalid Input. Reverting to default.')
        argVariable = 0

if argVariable == 0:
    print('We\'ll collect a few values on our own.')
    listToBeTested = dogRandom.getRandomList(6)

print('Adding the first element to new list.')
listOfChosenOnes.append(listToBeTested[0])
print('Adding the last element to new list')
listOfChosenOnes.append(listToBeTested[len(listToBeTested)-1])

print('tested body of elements')
dogUtil.walkList(listToBeTested)

print('first and last elements')
dogUtil.walkList(listOfChosenOnes)
コード例 #4
0
import sys
import dogRandom

if len(sys.argv) == 1 or len(sys.argv) == 2:
    print(
        'Consider using the command line argument \'python3 ex5.py <listLength1> <listLength2>'
    )
    print('Creating two random lists, lengths 10 and 12.')
    listLength1 = 10
    listLength2 = 12

if len(sys.argv) == 3:
    try:  #Because it's user input, we have to check it a bit.
        listLength1 = int(sys.argv[1])
        listLength2 = int(sys.argv[2])
    except:
        print('Your entry was not a number. Defaulting to a random number.')
        listLength1 = 10
        listLength2 = 12

randomListA = dogRandom.getRandomList(listLength1, 0,
                                      50)  #using new overloaded method
randomListB = dogRandom.getRandomList(listLength2, 0,
                                      50)  #using new overloaded method

for index, element in enumerate(randomListA):
    if element in randomListB:
        print('Found Mutually Between Lists: ', element)
コード例 #5
0
sysRandomList = []
howManySysRandom = 1000

if len(sys.argv) > 1:
    howManyRandom = sys.argv[
        1]  #if someone wants to force the issue, let them set the number
    howManySysRandom = int(howManyRandom)

print('Collecting', howManySysRandom,
      'random values from Python\'s built in library')

while howManySysRandom != 0:  #build our Python offering
    sysRandomList.append(random.randint(0, 9))
    howManySysRandom = howManySysRandom - 1

listOfRandoms = dogRandom.getRandomList(
    howManyRandom)  #let the dogRandom take a shot
print('Collecting', howManyRandom,
      'numbers from random.org, generated from atmospheric noise.')

#print(refinedRandoms) #just to show our receipts, for debugging purposes

print('Harnessing this vast technology, let\'s see how many are over 5.'
      )  #HARNESS VAST SENSORS SIFTING SPACE FOR UTILITY

totalExceedingDogRandom = 0  #set an old school sentinel.

for index, element in enumerate(
        listOfRandoms
):  #enumerate was new to me here. index is a value that enumerate creates.
    if int(element) >= 5:
        #print('Value ',element,' found in element',index) #this is costly in screen real estate.