From the class Code as a Liberal Art · Spring 2022
in_class.py
# First Python program of the semester!
x = 5
if x > 5:
print("Greater")
else:
print("Less than")
unit1_smallest_number.py
number_list = [ 234, 2, 6, 42, 1, 124, 687, 5, 674, 45, 67, 99, 23 ]
smallest_number = number_list[0]
for n in number_list:
if n < smallest_number:
smallest_number = n
print("The smallest number in this list is: " + str(smallest_number) )
smallest_number = number_list[0]
for n in number_list:
if n > 100 and n < smallest_number:
smallest_number = n
print("The smallest number in this list greater than 100 is: " + str(smallest_number) )
unit1_hw1_part1.py
#Experiments with search
from unit1_tutorial1_data import *
#a.
smallest_number = number_list[0]
for n in number_list:
if n < smallest_number:
smallest_number = n
print("The smallest number in this list is: " + str(smallest_number) )
# The smallest number in this list is: 43
#b.
smallest_number = number_list[0]
for n in number_list:
if n > 500 and n < smallest_number:
smallest_number = n
print("The smallest number in this list greater than 500 is: " + str(smallest_number) )
#The smallest number in this list greater than 500 is: 501
#c.
smallest_number = number_list[0]
for n in number_list:
if n%2 == 0 and n < smallest_number:
smallest_number = n
print("The smallest even number in this list is: " + str(smallest_number) )
#The smallest even number in this list is: 44
#d.
word_list.sort()
last_alphabetical_word = word_list[-1]
print("The last alphabetical word in this list is: " + str(last_alphabetical_word) )
#e.
longest_word = word_list[0]
for n in word_list:
if len(n) > len(longest_word):
longest_word = n
print("The longest word in this list is: " + str(longest_word) )
#The longest word in this list is: recommendation
unit1_tutorial1_data.py
# A randomly generated list of 1000 numbers between 0 and 1000
number_list = [ 589, 354, 184, 749, 147, 752, 585, 386, 280, 218, 550, 778, 491, 859, 901, 225, 248, 844, 176, 441, 151, 731, 71, 51, 440, 537, 570, 119, 892, 812, 245, 544, 129, 477, 421, 239, 671, 518, 530, 626, 140, 345, 476, 539, 349, 692, 483, 709, 587, 757, 117, 761, 873, 133, 581, 837, 926, 532, 863, 458, 637, 695, 62, 138, 896, 743, 364, 201, 975, 597, 868, 344, 558, 639, 349, 621, 668, 95, 971, 524, 201, 287, 475, 239, 358, 397, 914, 430, 123, 604, 739, 659, 526, 670, 852, 477, 825, 440, 581, 425, 129, 342, 832, 584, 831, 506, 955, 605, 243, 471, 250, 184, 570, 447, 831, 143, 184, 307, 780, 735, 140, 305, 940, 389, 68, 647, 270, 963, 136, 913, 535, 619, 288, 921, 437, 560, 357, 426, 571, 655, 364, 736, 247, 316, 457, 493, 255, 79, 642, 238, 596, 616, 520, 72, 771, 433, 244, 628, 861, 649, 212, 708, 732, 941, 142, 432, 477, 814, 573, 916, 810, 555, 340, 818, 505, 893, 406, 501, 910, 721, 568, 72, 194, 683, 272, 357, 315, 679, 547, 484, 97, 68, 909, 127, 508, 770, 614, 364, 488, 594, 215, 195, 219, 141, 269, 326, 265, 848, 743, 166, 72, 70, 479, 883, 623, 585, 968, 886, 474, 117, 271, 587, 678, 763, 824, 922, 467, 298, 616, 906, 821, 444, 115, 99, 509, 435, 181, 656, 209, 616, 382, 367, 572, 850, 628, 860, 79, 635, 226, 430, 335, 512, 969, 719, 251, 544, 256, 628, 677, 155, 670, 386, 474, 978, 492, 134, 208, 769, 729, 791, 528, 82, 902, 674, 843, 909, 129, 805, 982, 627, 84, 413, 546, 798, 424, 243, 531, 214, 769, 147, 752, 624, 686, 817, 191, 435, 461, 349, 529, 747, 59, 757, 472, 950, 817, 862, 649, 779, 577, 309, 696, 685, 854, 214, 345, 861, 830, 796, 143, 828, 207, 721, 234, 303, 544, 773, 238, 990, 976, 725, 795, 154, 448, 284, 881, 318, 466, 263, 239, 837, 960, 797, 766, 778, 600, 854, 239, 828, 793, 360, 544, 385, 62, 135, 836, 799, 789, 374, 659, 92, 872, 744, 433, 796, 948, 106, 618, 551, 606, 726, 667, 853, 594, 59, 901, 455, 783, 634, 752, 146, 940, 174, 550, 756, 207, 553, 45, 43, 901, 107, 734, 289, 367, 534, 785, 947, 599, 318, 441, 461, 106, 597, 605, 466, 678, 603, 417, 231, 986, 464, 174, 950, 248, 517, 141, 564, 405, 111, 263, 562, 244, 605, 287, 885, 138, 523, 581, 210, 52, 549, 91, 477, 780, 98, 568, 316, 329, 968, 793, 810, 397, 155, 590, 917, 267, 218, 391, 598, 386, 80, 469, 852, 579, 262, 810, 630, 617, 181, 897, 572, 854, 609, 681, 932, 183, 300, 133, 612, 844, 174, 949, 131, 717, 896, 575, 634, 219, 691, 511, 122, 892, 287, 813, 515, 926, 778, 431, 352, 812, 72, 952, 363, 952, 542, 48, 277, 291, 285, 327, 724, 374, 351, 929, 354, 783, 608, 152, 886, 935, 781, 428, 918, 692, 958, 664, 794, 64, 621, 500, 205, 992, 296, 380, 505, 796, 117, 567, 593, 262, 722, 918, 79, 753, 748, 654, 342, 288, 301, 289, 689, 230, 370, 176, 558, 284, 962, 60, 856, 807, 631, 215, 454, 950, 247, 52, 860, 538, 425, 310, 598, 404, 502, 896, 457, 451, 255, 960, 156, 213, 72, 68, 386, 118, 409, 317, 229, 229, 137, 711, 183, 631, 499, 260, 798, 385, 307, 808, 286, 590, 784, 187, 293, 269, 782, 577, 953, 401, 731, 943, 753, 136, 985, 394, 510, 185, 728, 893, 585, 895, 78, 876, 149, 845, 650, 426, 554, 730, 926, 648, 367, 547, 840, 306, 76, 510, 322, 843, 296, 70, 749, 270, 78, 484, 374, 884, 380, 983, 618, 906, 566, 677, 871, 863, 414, 760, 566, 51, 66, 630, 909, 802, 464, 430, 320, 669, 185, 747, 355, 785, 49, 161, 357, 880, 472, 61, 423, 77, 278, 752, 44, 254, 251, 532, 335, 499, 228, 533, 861, 118, 618, 185, 152, 969, 698, 75, 698, 748, 264, 899, 801, 832, 747, 821, 332, 673, 329, 752, 566, 776, 535, 951, 249, 369, 473, 175, 875, 840, 542, 319, 338, 886, 266, 373, 501, 153, 635, 255, 384, 860, 466, 179, 945, 319, 662, 282, 420, 439, 525, 835, 627, 729, 645, 568, 474, 615, 932, 875, 237, 865, 904, 53, 607, 511, 301, 803, 238, 549, 282, 388, 143, 573, 241, 925, 43, 686, 754, 71, 948, 81, 742, 664, 548, 806, 598, 488, 860, 419, 691, 967, 216, 721, 409, 994, 875, 227, 268, 129, 179, 216, 920, 672, 635, 511, 497, 742, 403, 629, 316, 950, 610, 624, 569, 660, 510, 576, 266, 932, 502, 189, 687, 341, 188, 660, 851, 904, 470, 67, 610, 442, 777, 468, 945, 121, 968, 371, 850, 203, 844, 964, 183, 813, 176, 771, 543, 430, 761, 951, 562, 658, 646, 417, 724, 432, 586, 268, 538, 834, 552, 78, 450, 429, 66, 552, 431, 466, 245, 536, 398, 871, 727, 351, 872, 95, 775, 723, 173, 830, 675, 756, 605, 674, 197, 111, 416, 91, 245, 161, 237, 396, 822, 789, 342, 826, 833, 400, 130, 379, 283, 965, 311, 910, 751, 988, 759, 421, 870, 595, 188, 212, 894, 580, 46, 119, 702, 412, 166, 68, 395, 647, 636, 786, 830, 661, 835, 493, 703, 61, 701, 296, 713, 975, 324, 711, 240, 653, 140, 169, 972, 58, 692, 611, 684, 578, 708, 914, 975, 938, 289, 442, 333, 599, 397, 57, 462, 658, 85, 992, 263, 485, 491, 694, 513, 861, 627, 294, 912, 242, 948, 561, 53, 669, 401, 411, 185, 175, 104, 886, 622, 840, 621, 444, 229, 638, 194, 247, 920, 214, 949, 890, 537, 666, 64, 443, 647, 445, 456, 837, 375, 822, 272, 240, 378, 821, 628, 625, 844, 963, 511, 756, 971, 350, 432, 86, 974, 886, 804, 860, 556, 261, 237]
# A randomly generated list of 50 words
word_list = [ "astonishing", "rehabilitation", "understanding", "mathematics", "liability", "obligation", "fashionable", "organisation", "evolution", "excavation", "constitution", "invisible", "implication", "academy", "appreciate", "aquarium", "generation", "reproduction", "accessible", "commemorate", "violation", "integration", "combination", "definition", "emergency", "deprivation", "vegetarian", "photocopy", "radiation", "admiration", "laboratory", "helicopter", "embarrassment", "experience", "hierarchy", "hospitality", "conventional", "deviation", "regulation", "indication", "acquisition", "ambiguous", "civilization", "exaggerate", "intermediate", "recommendation", "casualty", "motivation", "manufacture", "deteriorate" ]
part1/unit1_hw3_part1.py
import sys
word_list = sys.argv
word_list.pop(0)
longest_word = word_list[0]
for n in word_list:
if len(n) > len(longest_word):
longest_word = n
print("The longest word in this list is: " + str(longest_word) )