├── Compulsory Projects ├── 01_madlibs.py ├── 02_guessnumber_computer.py ├── 03_rock_paper_scissors.py └── 04_hangman │ ├── __pycache__ │ ├── hangman_visual.cpython-312.pyc │ └── words.cpython-312.pyc │ ├── hangman.py │ ├── hangman_visual.py │ └── words.py ├── Homework Projects ├── 00_intro_python │ ├── 01_add_two_numbers.py │ ├── 02_agreement_bot.py │ ├── 03_fahrenheit_to_celsius.py │ ├── 04_how_old_are_they.py │ ├── 05_triangle_perimeter.py │ └── 06_square_number.py ├── 01_expressions │ ├── 01_dicesimulator.py │ ├── 02_e=mc2.py │ ├── 03_feet_to_inches.py │ ├── 04_pythagorean_theorem.py │ ├── 05_remainder_division.py │ ├── 06_rolldice.py │ ├── 06_seconds_in_year.py │ └── 07_tiny_mad_lib.py ├── 02_lists │ ├── 01_add_many_number.py │ ├── 02_double_list.py │ ├── 03_erase_canvas.py │ ├── 04_flowing_with_data_structures.py │ ├── 05_get_first_element.py │ ├── 06_get_last_element.py │ ├── 07_get_list.py │ └── 08_shorten.py ├── 03_if_statements │ ├── 01_print_events.py │ ├── 02_international_voting_age.py │ ├── 03_leap_year.py │ ├── 04_tall_enough_to_ride.py │ └── 05_random_numbers.py ├── 04_dictionaries │ ├── 00_count_nums.py │ ├── 01_phonebook.py │ ├── 02_pop_up_shop.py │ └── 03_powerful_passwords.py ├── 05_loops_control_flow │ ├── 00_guess_my_number.py │ ├── 01_fibonacci.py │ ├── 02_print_events.py │ ├── 03_wholesome_machine.py │ ├── 04_liftoff.py │ └── 05_double_it.py ├── 06_functions │ ├── 00_averages.py │ ├── 01_chaotic_counting.py │ ├── 02_count_even.py │ ├── 04_double.py │ ├── 05_get_name.py │ ├── 06_is_odd.py │ ├── 07_print_divisor.py │ ├── 08_print_multiple.py │ ├── 09_sentence_generator.py │ └── 10_print_ones_digit.py └── 07_information_flow │ ├── 00_choosing_returns.py │ ├── 01_greetings.py │ ├── 02_in_range.py │ ├── 03_in_stock.py │ ├── 04_multiple_returns.py │ └── 05_subtract_7.py ├── Online Class Projects └── 01_basics │ ├── 00_joke_bot.py │ ├── 01_double_it.py │ ├── 02_liftoff.py │ ├── 03_guess_my_number.py │ └── 04_random_numbers.py ├── README.md └── favicon.ico /Compulsory Projects/01_madlibs.py: -------------------------------------------------------------------------------- 1 | """ 2 | Very Beginner Python Project by Kylie Ying 3 | Madlibs using string concatenation 4 | 5 | YouTube Kylie Ying: https://www.youtube.com/ycubed 6 | Twitch KylieYing: https://www.twitch.tv/kylieying 7 | Twitter @kylieyying: https://twitter.com/kylieyying 8 | Instagram @kylieyying: https://www.instagram.com/kylieyying/ 9 | Website: https://www.kylieying.com 10 | Github: https://www.github.com/kying18 11 | Programmer Beast Mode Spotify playlist: https://open.spotify.com/playlist/4Akns5EUb3gzmlXIdsJkPs?si=qGc4ubKRRYmPHAJAIrCxVQ 12 | """ 13 | # # string concatenation (aka how to put strings together) 14 | # # suppose we want to create a string that says "subscribe to _____ " 15 | # youtuber = "Kylie Ying" # some string variable 16 | 17 | # # a few ways to do this 18 | # print("subscribe to " + youtuber) 19 | # print("subscribe to {}".format(youtuber)) 20 | # print(f"subscribe to {youtuber}") 21 | 22 | adj = input("Adjective: ") 23 | verb1 = input("Verb: ") 24 | verb2 = input("Verb: ") 25 | famous_person = input("Famous person: ") 26 | 27 | madlib = f"Computer programming is so {adj}! It makes me so excited all the time because \ 28 | I love to {verb1}. Stay hydrated and {verb2} like you are {famous_person}!" 29 | 30 | print(madlib) -------------------------------------------------------------------------------- /Compulsory Projects/02_guessnumber_computer.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess(x): 4 | random_number = random.randint(1, x) 5 | guess = 0 6 | while guess != random_number: 7 | guess = int(input(f'Guess a number between 1 and {x}: ')) 8 | if guess < random_number: 9 | print('Sorry, guess again. Too low.') 10 | elif guess > random_number: 11 | print('Sorry, guess again. Too high.') 12 | 13 | print(f'Yay, congrats. You have guessed the number {random_number} correctly!!') 14 | 15 | def computer_guess(x): 16 | low = 1 17 | high = x 18 | feedback = '' 19 | while feedback != 'c': 20 | if low != high: 21 | guess = random.randint(low, high) 22 | else: 23 | guess = low # could also be high b/c low = high 24 | feedback = input(f'Is {guess} too high (H), too low (L), or correct (C)?? ').lower() 25 | if feedback == 'h': 26 | high = guess - 1 27 | elif feedback == 'l': 28 | low = guess + 1 29 | 30 | print(f'Yay! The computer guessed your number, {guess}, correctly!') 31 | 32 | 33 | guess(10) -------------------------------------------------------------------------------- /Compulsory Projects/03_rock_paper_scissors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Implementation of rock, paper, scissors by Kylie Ying 3 | 4 | YouTube Kylie Ying: https://www.youtube.com/ycubed 5 | Twitch KylieYing: https://www.twitch.tv/kylieying 6 | Twitter @kylieyying: https://twitter.com/kylieyying 7 | Instagram @kylieyying: https://www.instagram.com/kylieyying/ 8 | Website: https://www.kylieying.com 9 | Github: https://www.github.com/kying18 10 | Programmer Beast Mode Spotify playlist: https://open.spotify.com/playlist/4Akns5EUb3gzmlXIdsJkPs?si=qGc4ubKRRYmPHAJAIrCxVQ 11 | """ 12 | 13 | import random 14 | 15 | def play(): 16 | user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n") 17 | computer = random.choice(['r', 'p', 's']) 18 | 19 | if user == computer: 20 | return 'It\'s a tie' 21 | 22 | # r > s, s > p, p > r 23 | if is_win(user, computer): 24 | return 'You won!' 25 | 26 | return 'You lost!' 27 | 28 | def is_win(player, opponent): 29 | # return true if player wins 30 | # r > s, s > p, p > r 31 | if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') \ 32 | or (player == 'p' and opponent == 'r'): 33 | return True 34 | 35 | print(play()) -------------------------------------------------------------------------------- /Compulsory Projects/04_hangman/__pycache__/hangman_visual.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RidaNaz/Python-Projects/51efcb121217f2b72a6c994934b8a65fe5f03b54/Compulsory Projects/04_hangman/__pycache__/hangman_visual.cpython-312.pyc -------------------------------------------------------------------------------- /Compulsory Projects/04_hangman/__pycache__/words.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RidaNaz/Python-Projects/51efcb121217f2b72a6c994934b8a65fe5f03b54/Compulsory Projects/04_hangman/__pycache__/words.cpython-312.pyc -------------------------------------------------------------------------------- /Compulsory Projects/04_hangman/hangman.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hangman implementation by Kylie Ying 3 | 4 | YouTube Kylie Ying: https://www.youtube.com/ycubed 5 | Twitch KylieYing: https://www.twitch.tv/kylieying 6 | Twitter @kylieyying: https://twitter.com/kylieyying 7 | Instagram @kylieyying: https://www.instagram.com/kylieyying/ 8 | Website: https://www.kylieying.com 9 | Github: https://www.github.com/kying18 10 | Programmer Beast Mode Spotify playlist: https://open.spotify.com/playlist/4Akns5EUb3gzmlXIdsJkPs?si=qGc4ubKRRYmPHAJAIrCxVQ 11 | """ 12 | 13 | import random 14 | from words import words 15 | from hangman_visual import lives_visual_dict 16 | import string 17 | 18 | 19 | def get_valid_word(words): 20 | word = random.choice(words) # randomly chooses something from the list 21 | while '-' in word or ' ' in word: 22 | word = random.choice(words) 23 | 24 | return word.upper() 25 | 26 | 27 | def hangman(): 28 | word = get_valid_word(words) 29 | word_letters = set(word) # letters in the word 30 | alphabet = set(string.ascii_uppercase) 31 | used_letters = set() # what the user has guessed 32 | 33 | lives = 7 34 | 35 | # getting user input 36 | while len(word_letters) > 0 and lives > 0: 37 | # letters used 38 | # ' '.join(['a', 'b', 'cd']) --> 'a b cd' 39 | print('You have', lives, 'lives left and you have used these letters: ', ' '.join(used_letters)) 40 | 41 | # what current word is (ie W - R D) 42 | word_list = [letter if letter in used_letters else '-' for letter in word] 43 | print(lives_visual_dict[lives]) 44 | print('Current word: ', ' '.join(word_list)) 45 | 46 | user_letter = input('Guess a letter: ').upper() 47 | if user_letter in alphabet - used_letters: 48 | used_letters.add(user_letter) 49 | if user_letter in word_letters: 50 | word_letters.remove(user_letter) 51 | print('') 52 | 53 | else: 54 | lives = lives - 1 # takes away a life if wrong 55 | print('\nYour letter,', user_letter, 'is not in the word.') 56 | 57 | elif user_letter in used_letters: 58 | print('\nYou have already used that letter. Guess another letter.') 59 | 60 | else: 61 | print('\nThat is not a valid letter.') 62 | 63 | # gets here when len(word_letters) == 0 OR when lives == 0 64 | if lives == 0: 65 | print(lives_visual_dict[lives]) 66 | print('You died, sorry. The word was', word) 67 | else: 68 | print('YAY! You guessed the word', word, '!!') 69 | 70 | 71 | if __name__ == '__main__': 72 | hangman() -------------------------------------------------------------------------------- /Compulsory Projects/04_hangman/hangman_visual.py: -------------------------------------------------------------------------------- 1 | lives_visual_dict = { 2 | 0: """ 3 | ___________ 4 | | / | 5 | |/ ( ) 6 | | | 7 | | / \\ 8 | | 9 | """, 10 | 1: """ 11 | ___________ 12 | | / | 13 | |/ ( ) 14 | | | 15 | | / 16 | | 17 | """, 18 | 2: """ 19 | ___________ 20 | | / | 21 | |/ ( ) 22 | | | 23 | | 24 | | 25 | """, 26 | 3: """ 27 | ___________ 28 | | / | 29 | |/ ( ) 30 | | 31 | | 32 | | 33 | """, 34 | 4: """ 35 | ___________ 36 | | / | 37 | |/ 38 | | 39 | | 40 | | 41 | """, 42 | 5: """ 43 | ___________ 44 | | / 45 | |/ 46 | | 47 | | 48 | | 49 | """, 50 | 6: """ 51 | | 52 | | 53 | | 54 | | 55 | | 56 | """, 57 | 7: "", 58 | } -------------------------------------------------------------------------------- /Compulsory Projects/04_hangman/words.py: -------------------------------------------------------------------------------- 1 | words = ["aback","abaft","abandoned","abashed","aberrant","abhorrent","abiding","abject","ablaze","able","abnormal","aboard","aboriginal","abortive","abounding","abrasive","abrupt","absent","absorbed","absorbing","abstracted","absurd","abundant","abusive","acceptable","accessible","accidental","accurate","acid","acidic","acoustic","acrid","actually","ad hoc","adamant","adaptable","addicted","adhesive","adjoining","adorable","adventurous","afraid","aggressive","agonizing","agreeable","ahead","ajar","alcoholic","alert","alike","alive","alleged","alluring","aloof","amazing","ambiguous","ambitious","amuck","amused","amusing","ancient","angry","animated","annoyed","annoying","anxious","apathetic","aquatic","aromatic","arrogant","ashamed","aspiring","assorted","astonishing","attractive","auspicious","automatic","available","average","awake","aware","awesome","awful","axiomatic","bad","barbarous","bashful","bawdy","beautiful","befitting","belligerent","beneficial","bent","berserk","best","better","bewildered","big","billowy","bite-sized","bitter","bizarre","black","black-and-white","bloody","blue","blue-eyed","blushing","boiling","boorish","bored","boring","bouncy","boundless","brainy","brash","brave","brawny","breakable","breezy","brief","bright","bright","broad","broken","brown","bumpy","burly","bustling","busy","cagey","calculating","callous","calm","capable","capricious","careful","careless","caring","cautious","ceaseless","certain","changeable","charming","cheap","cheerful","chemical","chief","childlike","chilly","chivalrous","chubby","chunky","clammy","classy","clean","clear","clever","cloistered","cloudy","closed","clumsy","cluttered","coherent","cold","colorful","colossal","combative","comfortable","common","complete","complex","concerned","condemned","confused","conscious","cooing","cool","cooperative","coordinated","courageous","cowardly","crabby","craven","crazy","creepy","crooked","crowded","cruel","cuddly","cultured","cumbersome","curious","curly","curved","curvy","cut","cute","cute","cynical","daffy","daily","damaged","damaging","damp","dangerous","dapper","dark","dashing","dazzling","dead","deadpan","deafening","dear","debonair","decisive","decorous","deep","deeply","defeated","defective","defiant","delicate","delicious","delightful","demonic","delirious","dependent","depressed","deranged","descriptive","deserted","detailed","determined","devilish","didactic","different","difficult","diligent","direful","dirty","disagreeable","disastrous","discreet","disgusted","disgusting","disillusioned","dispensable","distinct","disturbed","divergent","dizzy","domineering","doubtful","drab","draconian","dramatic","dreary","drunk","dry","dull","dusty","dusty","dynamic","dysfunctional","eager","early","earsplitting","earthy","easy","eatable","economic","educated","efficacious","efficient","eight","elastic","elated","elderly","electric","elegant","elfin","elite","embarrassed","eminent","empty","enchanted","enchanting","encouraging","endurable","energetic","enormous","entertaining","enthusiastic","envious","equable","equal","erect","erratic","ethereal","evanescent","evasive","even","excellent","excited","exciting","exclusive","exotic","expensive","extra-large","extra-small","exuberant","exultant","fabulous","faded","faint","fair","faithful","fallacious","false","familiar","famous","fanatical","fancy","fantastic","far","far-flung","fascinated","fast","fat","faulty","fearful","fearless","feeble","feigned","female","fertile","festive","few","fierce","filthy","fine","finicky","first","five","fixed","flagrant","flaky","flashy","flat","flawless","flimsy","flippant","flowery","fluffy","fluttering","foamy","foolish","foregoing","forgetful","fortunate","four","frail","fragile","frantic","free","freezing","frequent","fresh","fretful","friendly","frightened","frightening","full","fumbling","functional","funny","furry","furtive","future","futuristic","fuzzy","gabby","gainful","gamy","gaping","garrulous","gaudy","general","gentle","giant","giddy","gifted","gigantic","glamorous","gleaming","glib","glistening","glorious","glossy","godly","good","goofy","gorgeous","graceful","grandiose","grateful","gratis","gray","greasy","great","greedy","green","grey","grieving","groovy","grotesque","grouchy","grubby","gruesome","grumpy","guarded","guiltless","gullible","gusty","guttural","habitual","half","hallowed","halting","handsome","handsomely","handy","hanging","hapless","happy","hard","hard-to-find","harmonious","harsh","hateful","heady","healthy","heartbreaking","heavenly","heavy","hellish","helpful","helpless","hesitant","hideous","high","highfalutin","high-pitched","hilarious","hissing","historical","holistic","hollow","homeless","homely","honorable","horrible","hospitable","hot","huge","hulking","humdrum","humorous","hungry","hurried","hurt","hushed","husky","hypnotic","hysterical","icky","icy","idiotic","ignorant","ill","illegal","ill-fated","ill-informed","illustrious","imaginary","immense","imminent","impartial","imperfect","impolite","important","imported","impossible","incandescent","incompetent","inconclusive","industrious","incredible","inexpensive","infamous","innate","innocent","inquisitive","insidious","instinctive","intelligent","interesting","internal","invincible","irate","irritating","itchy","jaded","jagged","jazzy","jealous","jittery","jobless","jolly","joyous","judicious","juicy","jumbled","jumpy","juvenile","kaput","keen","kind","kindhearted","kindly","knotty","knowing","knowledgeable","known","labored","lackadaisical","lacking","lame","lamentable","languid","large","last","late","laughable","lavish","lazy","lean","learned","left","legal","lethal","level","lewd","light","like","likeable","limping","literate","little","lively","lively","living","lonely","long","longing","long-term","loose","lopsided","loud","loutish","lovely","loving","low","lowly","lucky","ludicrous","lumpy","lush","luxuriant","lying","lyrical","macabre","macho","maddening","madly","magenta","magical","magnificent","majestic","makeshift","male","malicious","mammoth","maniacal","many","marked","massive","married","marvelous","material","materialistic","mature","mean","measly","meaty","medical","meek","mellow","melodic","melted","merciful","mere","messy","mighty","military","milky","mindless","miniature","minor","miscreant","misty","mixed","moaning","modern","moldy","momentous","motionless","mountainous","muddled","mundane","murky","mushy","mute","mysterious","naive","nappy","narrow","nasty","natural","naughty","nauseating","near","neat","nebulous","necessary","needless","needy","neighborly","nervous","new","next","nice","nifty","nimble","nine","nippy","noiseless","noisy","nonchalant","nondescript","nonstop","normal","nostalgic","nosy","noxious","null","numberless","numerous","nutritious","nutty","oafish","obedient","obeisant","obese","obnoxious","obscene","obsequious","observant","obsolete","obtainable","oceanic","odd","offbeat","old","old-fashioned","omniscient","one","onerous","open","opposite","optimal","orange","ordinary","organic","ossified","outgoing","outrageous","outstanding","oval","overconfident","overjoyed","overrated","overt","overwrought","painful","painstaking","pale","paltry","panicky","panoramic","parallel","parched","parsimonious","past","pastoral","pathetic","peaceful","penitent","perfect","periodic","permissible","perpetual","petite","petite","phobic","physical","picayune","pink","piquant","placid","plain","plant","plastic","plausible","pleasant","plucky","pointless","poised","polite","political","poor","possessive","possible","powerful","precious","premium","present","pretty","previous","pricey","prickly","private","probable","productive","profuse","protective","proud","psychedelic","psychotic","public","puffy","pumped","puny","purple","purring","pushy","puzzled","puzzling","quack","quaint","quarrelsome","questionable","quick","quickest","quiet","quirky","quixotic","quizzical","rabid","racial","ragged","rainy","rambunctious","rampant","rapid","rare","raspy","ratty","ready","real","rebel","receptive","recondite","red","redundant","reflective","regular","relieved","remarkable","reminiscent","repulsive","resolute","resonant","responsible","rhetorical","rich","right","righteous","rightful","rigid","ripe","ritzy","roasted","robust","romantic","roomy","rotten","rough","round","royal","ruddy","rude","rural","rustic","ruthless","sable","sad","safe","salty","same","sassy","satisfying","savory","scandalous","scarce","scared","scary","scattered","scientific","scintillating","scrawny","screeching","second","second-hand","secret","secretive","sedate","seemly","selective","selfish","separate","serious","shaggy","shaky","shallow","sharp","shiny","shivering","shocking","short","shrill","shut","shy","sick","silent","silent","silky","silly","simple","simplistic","sincere","six","skillful","skinny","sleepy","slim","slimy","slippery","sloppy","slow","small","smart","smelly","smiling","smoggy","smooth","sneaky","snobbish","snotty","soft","soggy","solid","somber","sophisticated","sordid","sore","sore","sour","sparkling","special","spectacular","spicy","spiffy","spiky","spiritual","spiteful","splendid","spooky","spotless","spotted","spotty","spurious","squalid","square","squealing","squeamish","staking","stale","standing","statuesque","steadfast","steady","steep","stereotyped","sticky","stiff","stimulating","stingy","stormy","straight","strange","striped","strong","stupendous","stupid","sturdy","subdued","subsequent","substantial","successful","succinct","sudden","sulky","super","superb","superficial","supreme","swanky","sweet","sweltering","swift","symptomatic","synonymous","taboo","tacit","tacky","talented","tall","tame","tan","tangible","tangy","tart","tasteful","tasteless","tasty","tawdry","tearful","tedious","teeny","teeny-tiny","telling","temporary","ten","tender","tense","tense","tenuous","terrible","terrific","tested","testy","thankful","therapeutic","thick","thin","thinkable","third","thirsty","thirsty","thoughtful","thoughtless","threatening","three","thundering","tidy","tight","tightfisted","tiny","tired","tiresome","toothsome","torpid","tough","towering","tranquil","trashy","tremendous","tricky","trite","troubled","truculent","true","truthful","two","typical","ubiquitous","ugliest","ugly","ultra","unable","unaccountable","unadvised","unarmed","unbecoming","unbiased","uncovered","understood","undesirable","unequal","unequaled","uneven","unhealthy","uninterested","unique","unkempt","unknown","unnatural","unruly","unsightly","unsuitable","untidy","unused","unusual","unwieldy","unwritten","upbeat","uppity","upset","uptight","used","useful","useless","utopian","utter","uttermost","vacuous","vagabond","vague","valuable","various","vast","vengeful","venomous","verdant","versed","victorious","vigorous","violent","violet","vivacious","voiceless","volatile","voracious","vulgar","wacky","waggish","waiting","wakeful","wandering","wanting","warlike","warm","wary","wasteful","watery","weak","wealthy","weary","well-groomed","well-made","well-off","well-to-do","wet","whimsical","whispering","white","whole","wholesale","wicked","wide","wide-eyed","wiggly","wild","willing","windy","wiry","wise","wistful","witty","woebegone","womanly","wonderful","wooden","woozy","workable","worried","worthless","wrathful","wretched","wrong","wry","yellow","yielding","young","youthful","yummy","zany","zealous","zesty","zippy","zonked","account","achiever","acoustics","act","action","activity","actor","addition","adjustment","advertisement","advice","aftermath","afternoon","afterthought","agreement","air","airplane","airport","alarm","amount","amusement","anger","angle","animal","ants","apparatus","apparel","appliance","approval","arch","argument","arithmetic","arm","army","art","attack","attraction","aunt","authority","babies","baby","back","badge","bag","bait","balance","ball","base","baseball","basin","basket","basketball","bat","bath","battle","bead","bear","bed","bedroom","beds","bee","beef","beginner","behavior","belief","believe","bell","bells","berry","bike","bikes","bird","birds","birth","birthday","bit","bite","blade","blood","blow","board","boat","bomb","bone","book","books","boot","border","bottle","boundary","box","boy","brake","branch","brass","breath","brick","bridge","brother","bubble","bucket","building","bulb","burst","bushes","business","butter","button","cabbage","cable","cactus","cake","cakes","calculator","calendar","camera","camp","can","cannon","canvas","cap","caption","car","card","care","carpenter","carriage","cars","cart","cast","cat","cats","cattle","cause","cave","celery","cellar","cemetery","cent","chalk","chance","change","channel","cheese","cherries","cherry","chess","chicken","chickens","children","chin","church","circle","clam","class","cloth","clover","club","coach","coal","coast","coat","cobweb","coil","collar","color","committee","company","comparison","competition","condition","connection","control","cook","copper","corn","cough","country","cover","cow","cows","crack","cracker","crate","crayon","cream","creator","creature","credit","crib","crime","crook","crow","crowd","crown","cub","cup","current","curtain","curve","cushion","dad","daughter","day","death","debt","decision","deer","degree","design","desire","desk","destruction","detail","development","digestion","dime","dinner","dinosaurs","direction","dirt","discovery","discussion","distance","distribution","division","dock","doctor","dog","dogs","doll","dolls","donkey","door","downtown","drain","drawer","dress","drink","driving","drop","duck","ducks","dust","ear","earth","earthquake","edge","education","effect","egg","eggnog","eggs","elbow","end","engine","error","event","example","exchange","existence","expansion","experience","expert","eye","eyes","face","fact","fairies","fall","fang","farm","fear","feeling","field","finger","finger","fire","fireman","fish","flag","flame","flavor","flesh","flight","flock","floor","flower","flowers","fly","fog","fold","food","foot","force","fork","form","fowl","frame","friction","friend","friends","frog","frogs","front","fruit","fuel","furniture","gate","geese","ghost","giants","giraffe","girl","girls","glass","glove","gold","government","governor","grade","grain","grandfather","grandmother","grape","grass","grip","ground","group","growth","guide","guitar","gun","hair","haircut","hall","hammer","hand","hands","harbor","harmony","hat","hate","head","health","heat","hill","history","hobbies","hole","holiday","home","honey","hook","hope","horn","horse","horses","hose","hospital","hot","hour","house","houses","humor","hydrant","ice","icicle","idea","impulse","income","increase","industry","ink","insect","instrument","insurance","interest","invention","iron","island","jail","jam","jar","jeans","jelly","jellyfish","jewel","join","judge","juice","jump","kettle","key","kick","kiss","kittens","kitty","knee","knife","knot","knowledge","laborer","lace","ladybug","lake","lamp","land","language","laugh","leather","leg","legs","letter","letters","lettuce","level","library","limit","line","linen","lip","liquid","loaf","lock","locket","look","loss","love","low","lumber","lunch","lunchroom","machine","magic","maid","mailbox","man","marble","mark","market","mask","mass","match","meal","measure","meat","meeting","memory","men","metal","mice","middle","milk","mind","mine","minister","mint","minute","mist","mitten","mom","money","monkey","month","moon","morning","mother","motion","mountain","mouth","move","muscle","name","nation","neck","need","needle","nerve","nest","night","noise","north","nose","note","notebook","number","nut","oatmeal","observation","ocean","offer","office","oil","orange","oranges","order","oven","page","pail","pan","pancake","paper","parcel","part","partner","party","passenger","payment","peace","pear","pen","pencil","person","pest","pet","pets","pickle","picture","pie","pies","pig","pigs","pin","pipe","pizzas","place","plane","planes","plant","plantation","plants","plastic","plate","play","playground","pleasure","plot","plough","pocket","point","poison","pollution","popcorn","porter","position","pot","potato","powder","power","price","produce","profit","property","prose","protest","pull","pump","punishment","purpose","push","quarter","quartz","queen","question","quicksand","quiet","quill","quilt","quince","quiver","rabbit","rabbits","rail","railway","rain","rainstorm","rake","range","rat","rate","ray","reaction","reading","reason","receipt","recess","record","regret","relation","religion","representative","request","respect","rest","reward","rhythm","rice","riddle","rifle","ring","rings","river","road","robin","rock","rod","roll","roof","room","root","rose","route","rub","rule","run","sack","sail","salt","sand","scale","scarecrow","scarf","scene","scent","school","science","scissors","screw","sea","seashore","seat","secretary","seed","selection","self","sense","servant","shade","shake","shame","shape","sheep","sheet","shelf","ship","shirt","shock","shoe","shoes","shop","show","side","sidewalk","sign","silk","silver","sink","sister","sisters","size","skate","skin","skirt","sky","slave","sleep","sleet","slip","slope","smash","smell","smile","smoke","snail","snails","snake","snakes","sneeze","snow","soap","society","sock","soda","sofa","son","song","songs","sort","sound","soup","space","spade","spark","spiders","sponge","spoon","spot","spring","spy","square","squirrel","stage","stamp","star","start","statement","station","steam","steel","stem","step","stew","stick","sticks","stitch","stocking","stomach","stone","stop","store","story","stove","stranger","straw","stream","street","stretch","string","structure","substance","sugar","suggestion","suit","summer","sun","support","surprise","sweater","swim","swing","system","table","tail","talk","tank","taste","tax","teaching","team","teeth","temper","tendency","tent","territory","test","texture","theory","thing","things","thought","thread","thrill","throat","throne","thumb","thunder","ticket","tiger","time","tin","title","toad","toe","toes","tomatoes","tongue","tooth","toothbrush","toothpaste","top","touch","town","toy","toys","trade","trail","train","trains","tramp","transport","tray","treatment","tree","trees","trick","trip","trouble","trousers","truck","trucks","tub","turkey","turn","twig","twist","umbrella","uncle","underwear","unit","use","vacation","value","van","vase","vegetable","veil","vein","verse","vessel","vest","view","visitor","voice","volcano","volleyball","voyage","walk","wall","war","wash","waste","watch","water","wave","waves","wax","way","wealth","weather","week","weight","wheel","whip","whistle","wilderness","wind","window","wine","wing","winter","wire","wish","woman","women","wood","wool","word","work","worm","wound","wren","wrench","wrist","writer","writing","yak","yam","yard","yarn","year","yoke","zebra","zephyr","zinc","zipper","zoo","accept","add","admire","admit","advise","afford","agree","alert","allow","amuse","analyse","announce","annoy","answer","apologise","appear","applaud","appreciate","approve","argue","arrange","arrest","arrive","ask","attach","attack","attempt","attend","attract","avoid","back","bake","balance","ban","bang","bare","bat","bathe","battle","beam","beg","behave","belong","bleach","bless","blind","blink","blot","blush","boast","boil","bolt","bomb","book","bore","borrow","bounce","bow","box","brake","branch","breathe","bruise","brush","bubble","bump","burn","bury","buzz","calculate","call","camp","care","carry","carve","cause","challenge","change","charge","chase","cheat","check","cheer","chew","choke","chop","claim","clap","clean","clear","clip","close","coach","coil","collect","colour","comb","command","communicate","compare","compete","complain","complete","concentrate","concern","confess","confuse","connect","consider","consist","contain","continue","copy","correct","cough","count","cover","crack","crash","crawl","cross","crush","cry","cure","curl","curve","cycle","dam","damage","dance","dare","decay","deceive","decide","decorate","delay","delight","deliver","depend","describe","desert","deserve","destroy","detect","develop","disagree","disappear","disapprove","disarm","discover","dislike","divide","double","doubt","drag","drain","dream","dress","drip","drop","drown","drum","dry","dust","earn","educate","embarrass","employ","empty","encourage","end","enjoy","enter","entertain","escape","examine","excite","excuse","exercise","exist","expand","expect","explain","explode","extend","face","fade","fail","fancy","fasten","fax","fear","fence","fetch","file","fill","film","fire","fit","fix","flap","flash","float","flood","flow","flower","fold","follow","fool","force","form","found","frame","frighten","fry","gather","gaze","glow","glue","grab","grate","grease","greet","grin","grip","groan","guarantee","guard","guess","guide","hammer","hand","handle","hang","happen","harass","harm","hate","haunt","head","heal","heap","heat","help","hook","hop","hope","hover","hug","hum","hunt","hurry","identify","ignore","imagine","impress","improve","include","increase","influence","inform","inject","injure","instruct","intend","interest","interfere","interrupt","introduce","invent","invite","irritate","itch","jail","jam","jog","join","joke","judge","juggle","jump","kick","kill","kiss","kneel","knit","knock","knot","label","land","last","laugh","launch","learn","level","license","lick","lie","lighten","like","list","listen","live","load","lock","long","look","love","man","manage","march","mark","marry","match","mate","matter","measure","meddle","melt","memorise","mend","mess up","milk","mine","miss","mix","moan","moor","mourn","move","muddle","mug","multiply","murder","nail","name","need","nest","nod","note","notice","number","obey","object","observe","obtain","occur","offend","offer","open","order","overflow","owe","own","pack","paddle","paint","park","part","pass","paste","pat","pause","peck","pedal","peel","peep","perform","permit","phone","pick","pinch","pine","place","plan","plant","play","please","plug","point","poke","polish","pop","possess","post","pour","practise","pray","preach","precede","prefer","prepare","present","preserve","press","pretend","prevent","prick","print","produce","program","promise","protect","provide","pull","pump","punch","puncture","punish","push","question","queue","race","radiate","rain","raise","reach","realise","receive","recognise","record","reduce","reflect","refuse","regret","reign","reject","rejoice","relax","release","rely","remain","remember","remind","remove","repair","repeat","replace","reply","report","reproduce","request","rescue","retire","return","rhyme","rinse","risk","rob","rock","roll","rot","rub","ruin","rule","rush","sack","sail","satisfy","save","saw","scare","scatter","scold","scorch","scrape","scratch","scream","screw","scribble","scrub","seal","search","separate","serve","settle","shade","share","shave","shelter","shiver","shock","shop","shrug","sigh","sign","signal","sin","sip","ski","skip","slap","slip","slow","smash","smell","smile","smoke","snatch","sneeze","sniff","snore","snow","soak","soothe","sound","spare","spark","sparkle","spell","spill","spoil","spot","spray","sprout","squash","squeak","squeal","squeeze","stain","stamp","stare","start","stay","steer","step","stir","stitch","stop","store","strap","strengthen","stretch","strip","stroke","stuff","subtract","succeed","suck","suffer","suggest","suit","supply","support","suppose","surprise","surround","suspect","suspend","switch","talk","tame","tap","taste","tease","telephone","tempt","terrify","test","thank","thaw","tick","tickle","tie","time","tip","tire","touch","tour","tow","trace","trade","train","transport","trap","travel","treat","tremble","trick","trip","trot","trouble","trust","try","tug","tumble","turn","twist","type","undress","unfasten","unite","unlock","unpack","untidy","use","vanish","visit","wail","wait","walk","wander","want","warm","warn","wash","waste","watch","water","wave","weigh","welcome","whine","whip","whirl","whisper","whistle","wink","wipe","wish","wobble","wonder","work","worry","wrap","wreck","wrestle","wriggle","x-ray","yawn","yell","zip","zoom"] -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/01_add_two_numbers.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | """This program adds two numbers entered by the user.""" 3 | print("This program adds two numbers.") 4 | 5 | # Get user inputs and convert them to integers 6 | num1 = int(input("Enter first number: ")) 7 | num2 = int(input("Enter second number: ")) 8 | 9 | # Calculate sum 10 | total = num1 + num2 11 | 12 | # Display result 13 | print(f"The total sum is: {total}") 14 | 15 | # Required to call the main function 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/02_agreement_bot.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | """An interactive bot that agrees with your favorite animal choice.""" 3 | print("🐾 Welcome to Agreement Bot! Let's talk animals 🐾") 4 | 5 | # Ask user for their favorite animal 6 | animal = input("What's your favorite animal? ").strip().capitalize() 7 | 8 | # Handle empty input 9 | if not animal: 10 | print("Oops! You didn't type anything 🐌") 11 | else: 12 | print(f"My favorite animal is also {animal}! 🐾") 13 | 14 | # Call the main function 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/03_fahrenheit_to_celsius.py: -------------------------------------------------------------------------------- 1 | 2 | def main(): 3 | """Converts temperature from Fahrenheit to Celsius with user input.""" 4 | print("🌡️ Fahrenheit to Celsius Converter 🌡️") 5 | 6 | try: 7 | # Get temperature from user and convert to float 8 | fahrenheit = float(input("Enter temperature in Fahrenheit: ")) 9 | 10 | # Apply conversion formula 11 | celsius = (fahrenheit - 32) * 5.0 / 9.0 12 | 13 | # Print the result rounded to 2 decimal places 14 | print(f"Temperature: {fahrenheit}°F = {celsius:.2f}°C") 15 | 16 | except ValueError: 17 | print("⚠️ Please enter a valid number (e.g., 98.6).") 18 | 19 | # Required to call the main function 20 | if __name__ == '__main__': 21 | main() -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/04_how_old_are_they.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | """Solves the age riddle by calculating and printing each friend's age.""" 3 | 4 | # Step-by-step age calculation based on the riddle 5 | anton = 21 6 | beth = anton + 6 7 | chen = beth + 20 8 | drew = chen + anton 9 | ethan = chen 10 | 11 | # Print results exactly as expected 12 | print(f"Anton is {anton}") 13 | print(f"Beth is {beth}") 14 | print(f"Chen is {chen}") 15 | print(f"Drew is {drew}") 16 | print(f"Ethan is {ethan}") 17 | 18 | # Required line to execute the main function 19 | if __name__ == '__main__': 20 | main() -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/05_triangle_perimeter.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | """Calculates and prints the perimeter of a triangle based on user input.""" 3 | 4 | print("🔺 Triangle Perimeter Calculator 🔺") 5 | 6 | try: 7 | # Input side lengths as floats 8 | side1 = float(input("What is the length of side 1? ")) 9 | side2 = float(input("What is the length of side 2? ")) 10 | side3 = float(input("What is the length of side 3? ")) 11 | 12 | # Calculate perimeter 13 | perimeter = side1 + side2 + side3 14 | 15 | # Display result formatted to 2 decimal places 16 | print(f"The perimeter of the triangle is {perimeter:.2f}") 17 | 18 | except ValueError: 19 | print("⚠️ Please enter valid numbers for side lengths.") 20 | 21 | # Required line to execute the main function 22 | if __name__ == '__main__': 23 | main() -------------------------------------------------------------------------------- /Homework Projects/00_intro_python/06_square_number.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | """Prompts the user for a number and prints its square.""" 3 | 4 | print("🔢 Square Calculator 🔢") 5 | 6 | try: 7 | # Get number from user 8 | num = float(input("Type a number to see its square: ")) 9 | 10 | # Compute the square 11 | square = num ** 2 12 | 13 | # Display result with 2 decimal places 14 | print(f"{num:.2f} squared is {square:.2f}") 15 | 16 | except ValueError: 17 | print("⚠️ Please enter a valid number.") 18 | 19 | # Required line to execute the main function 20 | if __name__ == '__main__': 21 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/01_dicesimulator.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | # Constant representing number of sides on a die 4 | NUM_SIDES = 6 5 | 6 | def roll_dice(): 7 | """ 8 | Simulates rolling two dice and prints the values and their sum. 9 | This demonstrates local variable scope inside a function. 10 | """ 11 | die1: int = random.randint(1, NUM_SIDES) 12 | die2: int = random.randint(1, NUM_SIDES) 13 | total: int = die1 + die2 14 | 15 | print(f"Rolled: Die1 = {die1}, Die2 = {die2} --> Total = {total}") 16 | 17 | def main(): 18 | # This die1 is local to main() and has no connection with die1 inside roll_dice() 19 | die1: int = 10 20 | print(f"[main()] Initial die1 value: {die1}\n") 21 | 22 | print("Rolling dice three times...\n") 23 | roll_dice() 24 | roll_dice() 25 | roll_dice() 26 | 27 | print(f"\n[main()] Final die1 value: {die1} (unchanged, because of variable scope)") 28 | 29 | # Entry point of the program 30 | if __name__ == '__main__': 31 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/02_e=mc2.py: -------------------------------------------------------------------------------- 1 | # Constant: Speed of light in meters per second 2 | C: int = 299_792_458 # Using underscores for readability (Python allows this) 3 | 4 | def main(): 5 | # Ask the user to enter the mass in kilograms 6 | mass_in_kg: float = float(input("Enter kilos of mass: ")) 7 | 8 | # Calculate energy using the famous formula: E = m * c^2 9 | energy_in_joules: float = mass_in_kg * (C ** 2) 10 | 11 | # Display breakdown of the calculation 12 | print("\ne = m * C^2...") 13 | print("m = " + str(mass_in_kg) + " kg") 14 | print("C = " + str(C) + " m/s") 15 | print(f"\n{energy_in_joules} joules of energy!") 16 | 17 | # Call the main function to run the program 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/01_expressions/03_feet_to_inches.py: -------------------------------------------------------------------------------- 1 | """ 2 | An example program with constants 3 | """ 4 | 5 | INCHES_IN_FOOT: int = 12 # Conversion factor. There are 12 inches for 1 foot. 6 | 7 | def main(): 8 | feet: float = float(input("Enter number of feet: ")) 9 | inches: float = feet * INCHES_IN_FOOT # Perform the conversion 10 | print("That is", inches, "inches!") 11 | 12 | 13 | # This provided line is required at the end of a Python file 14 | # to call the main() function. 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/04_pythagorean_theorem.py: -------------------------------------------------------------------------------- 1 | import math # Import the math library so we can use the sqrt function 2 | 3 | def main(): 4 | # Get the two side lengths from the user and cast them to be numbers 5 | ab: float = float(input("Enter the length of AB: ")) 6 | ac: float = float(input("Enter the length of AC: ")) 7 | 8 | # Calculate the hypotenuse using the two sides and print it out 9 | bc: float = math.sqrt(ab**2 + ac**2) 10 | print("The length of BC (the hypotenuse) is: " + str(bc)) 11 | 12 | 13 | # There is no need to edit code beyond this point 14 | 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/05_remainder_division.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Get the numbers we want to divide 3 | dividend: int = int(input("Please enter an integer to be divided: ")) 4 | divisor: int = int(input("Please enter an integer to divide by: ")) 5 | 6 | quotient: int = dividend // divisor # Divide with no remainder/decimals (integer division) 7 | remainder: int = dividend % divisor # Get the remainder of the division (modulo) 8 | 9 | print("The result of this division is " + str(quotient) + " with a remainder of " + str(remainder)) 10 | 11 | 12 | # This provided line is required at the end of a Python file 13 | # to call the main() function. 14 | if __name__ == '__main__': 15 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/06_rolldice.py: -------------------------------------------------------------------------------- 1 | import random # Import the random library to simulate dice rolls 2 | 3 | # Number of sides on each die to roll 4 | NUM_SIDES: int = 6 5 | 6 | def main(): 7 | # Roll two dice 8 | die1: int = random.randint(1, NUM_SIDES) 9 | die2: int = random.randint(1, NUM_SIDES) 10 | 11 | # Get their total 12 | total: int = die1 + die2 13 | 14 | # Print out the results 15 | print("Dice have", NUM_SIDES, "sides each.") 16 | print("First die:", die1) 17 | print("Second die:", die2) 18 | print("Total of two dice:", total) 19 | 20 | 21 | # This provided line is required at the end of a Python file 22 | # to call the main() function. 23 | if __name__ == '__main__': 24 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/06_seconds_in_year.py: -------------------------------------------------------------------------------- 1 | # Useful constants to help make the math easier and cleaner! 2 | DAYS_PER_YEAR: int = 365 3 | HOURS_PER_DAY: int = 24 4 | MIN_PER_HOUR: int = 60 5 | SEC_PER_MIN: int = 60 6 | 7 | def main(): 8 | # We can get the number of seconds per year by multiplying the handy constants above! 9 | total_seconds_in_year: int = DAYS_PER_YEAR * HOURS_PER_DAY * MIN_PER_HOUR * SEC_PER_MIN 10 | print("There are " + str(total_seconds_in_year) + " seconds in a year!") 11 | 12 | # This provided line is required at the end of a Python file to call the main() function. 13 | if __name__ == '__main__': 14 | main() -------------------------------------------------------------------------------- /Homework Projects/01_expressions/07_tiny_mad_lib.py: -------------------------------------------------------------------------------- 1 | # Starting sentence part 2 | SENTENCE_START: str = "Panaversity is fun. I learned to program and used Python to make my " # adjective noun verb 3 | 4 | def main(): 5 | # Get the three inputs from the user to make the adlib 6 | adjective: str = input("Please type an adjective and press enter. ") 7 | noun: str = input("Please type a noun and press enter. ") 8 | verb: str = input("Please type a verb and press enter. ") 9 | 10 | # Join the inputs together with the sentence starter 11 | print(SENTENCE_START + adjective + " " + noun + " " + verb + "!") 12 | 13 | # This provided line is required at the end of a Python file to call the main() function. 14 | if __name__ == '__main__': 15 | main() -------------------------------------------------------------------------------- /Homework Projects/02_lists/01_add_many_number.py: -------------------------------------------------------------------------------- 1 | def add_many_numbers(numbers) -> int: 2 | """ 3 | Takes in a list of numbers and returns the sum of those numbers. 4 | """ 5 | total_so_far: int = 0 6 | for number in numbers: 7 | total_so_far += number 8 | return total_so_far 9 | 10 | 11 | def main(): 12 | numbers: list[int] = [1, 2, 3, 4, 5] # Create a list of numbers 13 | sum_of_numbers: int = add_many_numbers(numbers) # Call the function to get the sum 14 | print(sum_of_numbers) # Output the sum 15 | 16 | 17 | # This provided line is required at the end of the Python file 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/02_lists/02_double_list.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | numbers: list[int] = [1, 2, 3, 4] # Create a list of numbers 3 | 4 | for i in range(len(numbers)): # Loop through each index of the list 5 | numbers[i] = numbers[i] * 2 # Double the value at each index 6 | 7 | print(numbers) # Print the updated list 8 | 9 | 10 | # This provided line is required at the end of the Python file 11 | if __name__ == '__main__': 12 | main() -------------------------------------------------------------------------------- /Homework Projects/02_lists/03_erase_canvas.py: -------------------------------------------------------------------------------- 1 | """ This program implements an 'eraser' on a canvas. 2 | 3 | The canvas consists of a grid of blue 'cells' which are drawn as rectangles on the screen. 4 | We then create an eraser rectangle which, when dragged around the canvas, sets all of the 5 | rectangles it is in contact with to white. """ 6 | 7 | from graphics import Canvas 8 | import time 9 | 10 | # Constants for canvas and object sizes 11 | CANVAS_WIDTH: int = 400 12 | CANVAS_HEIGHT: int = 400 13 | CELL_SIZE: int = 40 14 | ERASER_SIZE: int = 20 15 | 16 | def erase_objects(canvas, eraser): 17 | """Erase objects in contact with the eraser.""" 18 | mouse_x = canvas.get_mouse_x() 19 | mouse_y = canvas.get_mouse_y() 20 | 21 | # Define the eraser's bounding box 22 | left_x = mouse_x 23 | top_y = mouse_y 24 | right_x = left_x + ERASER_SIZE 25 | bottom_y = top_y + ERASER_SIZE 26 | 27 | # Find all shapes the eraser overlaps with 28 | overlapping_objects = canvas.find_overlapping(left_x, top_y, right_x, bottom_y) 29 | 30 | # Change color of all overlapping shapes to white (except the eraser itself) 31 | for obj in overlapping_objects: 32 | if obj != eraser: 33 | canvas.set_color(obj, 'white') 34 | 35 | def main(): 36 | canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT) 37 | 38 | # Calculate grid dimensions 39 | num_rows = CANVAS_HEIGHT // CELL_SIZE 40 | num_cols = CANVAS_WIDTH // CELL_SIZE 41 | 42 | # Draw the grid of blue cells 43 | for row in range(num_rows): 44 | for col in range(num_cols): 45 | left_x = col * CELL_SIZE 46 | top_y = row * CELL_SIZE 47 | right_x = left_x + CELL_SIZE 48 | bottom_y = top_y + CELL_SIZE 49 | canvas.create_rectangle(left_x, top_y, right_x, bottom_y, 'blue') 50 | 51 | canvas.wait_for_click() 52 | 53 | # Get initial position to place the eraser 54 | start_x, start_y = canvas.get_last_click() 55 | 56 | # Create the pink eraser 57 | eraser = canvas.create_rectangle( 58 | start_x, 59 | start_y, 60 | start_x + ERASER_SIZE, 61 | start_y + ERASER_SIZE, 62 | 'pink' 63 | ) 64 | 65 | # Continuously move the eraser with the mouse and erase touched cells 66 | while True: 67 | mouse_x = canvas.get_mouse_x() 68 | mouse_y = canvas.get_mouse_y() 69 | canvas.moveto(eraser, mouse_x, mouse_y) 70 | 71 | erase_objects(canvas, eraser) 72 | 73 | time.sleep(0.05) 74 | 75 | # Required boilerplate 76 | if __name__ == '__main__': 77 | main() -------------------------------------------------------------------------------- /Homework Projects/02_lists/04_flowing_with_data_structures.py: -------------------------------------------------------------------------------- 1 | def add_three_copies(my_list, data): 2 | # Adds three copies of the data to the list (in-place change) 3 | for i in range(3): 4 | my_list.append(data) 5 | 6 | ########## No need to edit code past this point 7 | 8 | def main(): 9 | message = input("Enter a message to copy: ") 10 | my_list = [] 11 | print("List before:", my_list) 12 | add_three_copies(my_list, message) 13 | print("List after:", my_list) 14 | 15 | if __name__ == "__main__": 16 | main() 17 | -------------------------------------------------------------------------------- /Homework Projects/02_lists/05_get_first_element.py: -------------------------------------------------------------------------------- 1 | def get_first_element(lst): 2 | """ 3 | Prints the first element of a provided list. 4 | """ 5 | print(lst[0]) 6 | 7 | # There is no need to edit code beyond this point 8 | 9 | def get_lst(): 10 | """ 11 | Prompts the user to enter one element of the list at a time and returns the resulting list. 12 | """ 13 | lst = [] 14 | elem: str = input("Please enter an element of the list or press enter to stop. ") 15 | while elem != "": 16 | lst.append(elem) 17 | elem = input("Please enter an element of the list or press enter to stop. ") 18 | return lst 19 | 20 | def main(): 21 | lst = get_lst() 22 | get_first_element(lst) 23 | 24 | if __name__ == '__main__': 25 | main() -------------------------------------------------------------------------------- /Homework Projects/02_lists/06_get_last_element.py: -------------------------------------------------------------------------------- 1 | def get_last_element(lst): 2 | """ 3 | Prints the last element of the provided list. 4 | """ 5 | # Option 1: Using positive index 6 | print(lst[len(lst) - 1]) 7 | 8 | # Option 2 (more Pythonic): 9 | # print(lst[-1]) # This also works perfectly! 10 | 11 | 12 | # No need to edit code below this point 13 | def get_lst(): 14 | """ 15 | Prompts the user to enter one element of the list at a time and returns the resulting list. 16 | """ 17 | lst = [] 18 | elem = input("Please enter an element of the list or press enter to stop. ") 19 | while elem != "": 20 | lst.append(elem) 21 | elem = input("Please enter an element of the list or press enter to stop. ") 22 | return lst 23 | 24 | 25 | def main(): 26 | lst = get_lst() 27 | get_last_element(lst) 28 | 29 | 30 | if __name__ == '__main__': 31 | main() -------------------------------------------------------------------------------- /Homework Projects/02_lists/07_get_list.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | lst = [] # Initialize an empty list 3 | 4 | val = input("Enter a value: ") # Ask the user for input 5 | while val: # Continue as long as the input is not empty 6 | lst.append(val) # Add the input to the list 7 | val = input("Enter a value: ") # Prompt again 8 | 9 | print("Here's the list:", lst) 10 | 11 | 12 | # This provided line is required at the end of the file 13 | if __name__ == '__main__': 14 | main() 15 | -------------------------------------------------------------------------------- /Homework Projects/02_lists/08_shorten.py: -------------------------------------------------------------------------------- 1 | MAX_LENGTH: int = 3 2 | 3 | def shorten(lst): 4 | while len(lst) > MAX_LENGTH: 5 | last_elem = lst.pop() # Remove the last element 6 | print(last_elem) # Print the removed element 7 | 8 | 9 | # No changes needed below this line 10 | 11 | def get_lst(): 12 | """ 13 | Prompts the user to enter one element of the list at a time and returns the resulting list. 14 | """ 15 | lst = [] 16 | elem = input("Please enter an element of the list or press enter to stop. ") 17 | while elem != "": 18 | lst.append(elem) 19 | elem = input("Please enter an element of the list or press enter to stop. ") 20 | return lst 21 | 22 | def main(): 23 | lst = get_lst() 24 | shorten(lst) 25 | 26 | if __name__ == '__main__': 27 | main() -------------------------------------------------------------------------------- /Homework Projects/03_if_statements/01_print_events.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Loop through the first 20 numbers and print their double (which gives even numbers) 3 | for i in range(20): 4 | print(i * 2) 5 | 6 | # Call the main function 7 | if __name__ == "__main__": 8 | main() 9 | -------------------------------------------------------------------------------- /Homework Projects/03_if_statements/02_international_voting_age.py: -------------------------------------------------------------------------------- 1 | # Defining the voting ages for each fictional country 2 | PETURKSBOUIPO_AGE = 16 3 | STANLAU_AGE = 25 4 | MAYENGUA_AGE = 48 5 | 6 | def main(): 7 | # Prompt the user for their age 8 | user_age = int(input("How old are you? ")) 9 | 10 | # Check if the user can vote in Peturksbouipo 11 | if user_age >= PETURKSBOUIPO_AGE: 12 | print("You can vote in Peturksbouipo where the voting age is " + str(PETURKSBOUIPO_AGE) + ".") 13 | else: 14 | print("You cannot vote in Peturksbouipo where the voting age is " + str(PETURKSBOUIPO_AGE) + ".") 15 | 16 | # Check if the user can vote in Stanlau 17 | if user_age >= STANLAU_AGE: 18 | print("You can vote in Stanlau where the voting age is " + str(STANLAU_AGE) + ".") 19 | else: 20 | print("You cannot vote in Stanlau where the voting age is " + str(STANLAU_AGE) + ".") 21 | 22 | # Check if the user can vote in Mayengua 23 | if user_age >= MAYENGUA_AGE: 24 | print("You can vote in Mayengua where the voting age is " + str(MAYENGUA_AGE) + ".") 25 | else: 26 | print("You cannot vote in Mayengua where the voting age is " + str(MAYENGUA_AGE) + ".") 27 | 28 | # Ensure the main function is called 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /Homework Projects/03_if_statements/03_leap_year.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Get the year to check from the user 3 | year = int(input('Please input a year: ')) 4 | 5 | if year % 4 == 0: # Checking whether the provided year is evenly divisible by 4 6 | if year % 100 == 0: # Checking whether the provided year is evenly divisible by 100 7 | if year % 400 == 0: # Checking whether the provided year is evenly divisible by 400 8 | print("That's a leap year!") 9 | else: # (Not divisible by 400) 10 | print("That's not a leap year.") 11 | else: # (Not divisible by 100) 12 | print("That's a leap year!") 13 | else: # (Not divisible by 4) 14 | print("That's not a leap year.") 15 | 16 | # Ensure the main function is called 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Homework Projects/03_if_statements/04_tall_enough_to_ride.py: -------------------------------------------------------------------------------- 1 | MINIMUM_HEIGHT : int = 50 # arbitrary units :) 2 | 3 | def tall_enough_extension(): 4 | while True: 5 | height_input = input("How tall are you? ") # Prompt for height input 6 | if height_input == "": # If the user enters nothing, stop the loop 7 | break 8 | height = float(height_input) # Convert height to float 9 | if height >= MINIMUM_HEIGHT: 10 | print("You're tall enough to ride!") 11 | else: 12 | print("You're not tall enough to ride, but maybe next year!") 13 | 14 | def main(): 15 | tall_enough_extension() 16 | 17 | # Ensure the main function is called 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/03_if_statements/05_random_numbers.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | N_NUMBERS : int = 10 4 | MIN_VALUE : int = 1 5 | MAX_VALUE : int = 100 6 | 7 | def main(): 8 | # Generate and print 10 random numbers in the range of 1 to 100 9 | for _ in range(N_NUMBERS): 10 | print(random.randint(MIN_VALUE, MAX_VALUE), end=" ") 11 | 12 | # Ensure the main function is called 13 | if __name__ == '__main__': 14 | main() 15 | -------------------------------------------------------------------------------- /Homework Projects/04_dictionaries/00_count_nums.py: -------------------------------------------------------------------------------- 1 | def get_user_numbers(): 2 | """ 3 | Create an empty list. 4 | Ask the user to input numbers and store them in a list. 5 | Once they enter a blank line, break out of the loop and return the list. 6 | """ 7 | user_numbers = [] 8 | while True: 9 | user_input = input("Enter a number: ") 10 | 11 | # If the user enters a blank line, break out of the loop and stop asking for input 12 | if user_input == "": 13 | break 14 | 15 | # Convert the user input to an integer and add it to the list 16 | num = int(user_input) 17 | user_numbers.append(num) 18 | 19 | return user_numbers 20 | 21 | def count_nums(num_lst): 22 | """ 23 | Create an empty dictionary. 24 | Loop over the list of numbers. 25 | If the number is not in the dictionary, add it as a key with a value of 1. 26 | If the number is in the dictionary, increment its value by 1. 27 | """ 28 | num_dict = {} 29 | for num in num_lst: 30 | if num not in num_dict: 31 | num_dict[num] = 1 32 | else: 33 | num_dict[num] += 1 34 | 35 | return num_dict 36 | 37 | def print_counts(num_dict): 38 | """ 39 | Loop over the dictionary and print out each key and its value. 40 | """ 41 | for num in num_dict: 42 | print(str(num) + " appears " + str(num_dict[num]) + " times.") 43 | 44 | def main(): 45 | """ 46 | Ask the user to input numbers and store them in a list. Once they enter a blank line, 47 | print out the number of times each number appeared in the list. 48 | """ 49 | user_numbers = get_user_numbers() 50 | num_dict = count_nums(user_numbers) 51 | print_counts(num_dict) 52 | 53 | # Python boilerplate. 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /Homework Projects/04_dictionaries/01_phonebook.py: -------------------------------------------------------------------------------- 1 | def read_phone_numbers(): 2 | """ 3 | Ask the user for names/numbers to store in a phonebook (dictionary). 4 | Returns the phonebook. 5 | """ 6 | phonebook = {} # Create an empty phonebook dictionary 7 | 8 | while True: 9 | name = input("Name: ") 10 | if name == "": 11 | break # Exit loop if an empty string is entered for the name 12 | number = input("Number: ") 13 | phonebook[name] = number # Add name and number to the phonebook 14 | 15 | return phonebook 16 | 17 | 18 | def print_phonebook(phonebook): 19 | """ 20 | Prints out all the names/numbers in the phonebook. 21 | """ 22 | for name in phonebook: 23 | print(f"{name} -> {phonebook[name]}") # Print each name with its corresponding phone number 24 | 25 | 26 | def lookup_numbers(phonebook): 27 | """ 28 | Allow the user to lookup phone numbers in the phonebook 29 | by looking up the number associated with a name. 30 | """ 31 | while True: 32 | name = input("Enter name to lookup: ") 33 | if name == "": 34 | break # Exit lookup loop if an empty string is entered 35 | if name not in phonebook: 36 | print(f"{name} is not in the phonebook") 37 | else: 38 | print(phonebook[name]) # Print the phone number associated with the name 39 | 40 | 41 | def main(): 42 | phonebook = read_phone_numbers() # Read phone numbers from the user 43 | print_phonebook(phonebook) # Print the phonebook 44 | lookup_numbers(phonebook) # Allow user to lookup numbers 45 | 46 | 47 | # Python boilerplate. 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /Homework Projects/04_dictionaries/02_pop_up_shop.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Dictionary storing fruit names as keys and their prices as values 3 | fruits = {'apple': 1.5, 'durian': 50, 'jackfruit': 80, 'kiwi': 1, 'rambutan': 1.5, 'mango': 5} 4 | 5 | total_cost = 0 # Initialize the total cost to 0 6 | # Loop through each fruit in the dictionary 7 | for fruit_name in fruits: 8 | price = fruits[fruit_name] # Get the price of the current fruit 9 | # Prompt the user for the quantity of the current fruit they want to buy 10 | amount_bought = int(input(f"How many ({fruit_name}) do you want to buy?: ")) 11 | # Add the cost of the current fruit to the total cost 12 | total_cost += (price * amount_bought) 13 | 14 | # Print the total cost 15 | print(f"Your total is ${total_cost}") 16 | 17 | # Python boilerplate to call the main function 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/04_dictionaries/03_powerful_passwords.py: -------------------------------------------------------------------------------- 1 | from hashlib import sha256 2 | 3 | def login(email, stored_logins, password_to_check): 4 | """ 5 | Returns True if the hash of the password we are checking matches the one in stored_logins 6 | for a specific email. Otherwise, returns False. 7 | 8 | email: the email we are checking the password for 9 | stored_logins: a dictionary pointing from an email to its hashed password 10 | password_to_check: a password we want to test alongside the email to login with 11 | """ 12 | 13 | # Check if the hash of the provided password matches the stored hash for that email 14 | if stored_logins[email] == hash_password(password_to_check): 15 | return True 16 | 17 | return False 18 | 19 | def hash_password(password): 20 | """ 21 | Takes in a password and returns the SHA256 hashed value for that specific password. 22 | 23 | Inputs: 24 | password: the password we want 25 | 26 | Outputs: 27 | the hashed form of the input password 28 | """ 29 | return sha256(password.encode()).hexdigest() 30 | 31 | def main(): 32 | # stored_logins is a dictionary with emails as keys and hashed passwords as values 33 | stored_logins = { 34 | "example@gmail.com": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", # hash of 'password' 35 | "code_in_placer@cip.org": "973607a4ae7b4cf7d96a100b0fb07e8519cc4f70441d41214a9f811577bb06cc", # hash of 'Karel' 36 | "student@stanford.edu": "882c6df720fd99f5eebb1581a1cf975625cea8a160283011c0b9512bb56c95fb" # hash of 'password' 37 | } 38 | 39 | # Test cases to verify login functionality 40 | print(login("example@gmail.com", stored_logins, "word")) # False (wrong password) 41 | print(login("example@gmail.com", stored_logins, "password")) # True (correct password) 42 | 43 | print(login("code_in_placer@cip.org", stored_logins, "Karel")) # True (correct password) 44 | print(login("code_in_placer@cip.org", stored_logins, "karel")) # False (case-sensitive) 45 | 46 | print(login("student@stanford.edu", stored_logins, "password")) # True (correct password) 47 | print(login("student@stanford.edu", stored_logins, "123!456?789")) # False (wrong password) 48 | 49 | 50 | # Python boilerplate to call the main function 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/00_guess_my_number.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def main(): 4 | # Generate the secret number at random between 1 and 99 5 | secret_number = random.randint(1, 99) 6 | 7 | print("I am thinking of a number between 1 and 99...") 8 | 9 | # Get user's guess 10 | guess = int(input("Enter a guess: ")) 11 | 12 | # Keep prompting until the guess matches the secret number 13 | while guess != secret_number: 14 | if guess < secret_number: 15 | print("Your guess is too low") 16 | else: 17 | print("Your guess is too high") 18 | 19 | print() # Print an empty line to tidy up the console for new guesses 20 | guess = int(input("Enter a new guess: ")) # Get a new guess from the user 21 | 22 | print("Congrats! The number was: " + str(secret_number)) 23 | 24 | # Python boilerplate to call the main function 25 | if __name__ == '__main__': 26 | main() 27 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/01_fibonacci.py: -------------------------------------------------------------------------------- 1 | MAX_TERM_VALUE = 10000 # Maximum value for the Fibonacci term 2 | 3 | def main(): 4 | curr_term = 0 # The 0th Fibonacci Number 5 | next_term = 1 # The 1st Fibonacci Number 6 | 7 | # Continue until the current term exceeds MAX_TERM_VALUE 8 | while curr_term <= MAX_TERM_VALUE: 9 | print(curr_term, end=" ") # Print the current term in the Fibonacci sequence 10 | term_after_next = curr_term + next_term # Calculate the next Fibonacci term 11 | curr_term = next_term # Move to the next term in the sequence 12 | next_term = term_after_next # Update the next term 13 | 14 | # Python boilerplate to call the main function 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/02_print_events.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # This for-loop starts at 0 and counts up to 19 (for a total of 20 numbers) 3 | for i in range(20): 4 | print(i * 2, end=" ") # Multiply the loop index by 2 to get the even number, print on the same line 5 | 6 | # Python boilerplate to call the main function 7 | if __name__ == "__main__": 8 | main() 9 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/03_wholesome_machine.py: -------------------------------------------------------------------------------- 1 | AFFIRMATION: str = "I am capable of doing anything I put my mind to." 2 | 3 | def main(): 4 | print("Please type the following affirmation: " + AFFIRMATION) 5 | 6 | user_feedback = input() # Get user's input 7 | while user_feedback != AFFIRMATION: # While the user's input isn't the affirmation 8 | # Tell the user that they did not type the affirmation correctly 9 | print("That was not the affirmation.") 10 | 11 | # Ask the user to type the affirmation again! 12 | print("Please type the following affirmation: " + AFFIRMATION) 13 | user_feedback = input() 14 | 15 | print("That's right! :)") 16 | 17 | # Call the main function when the script runs 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/04_liftoff.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Countdown from 10 to 1 using a for loop 3 | for i in range(10, 0, -1): # Starts at 10 and decrements to 1 4 | print(i) 5 | 6 | # After the countdown, print "Liftoff!" 7 | print("Liftoff!") 8 | 9 | # Call the main function when the script runs 10 | if __name__ == '__main__': 11 | main() 12 | -------------------------------------------------------------------------------- /Homework Projects/05_loops_control_flow/05_double_it.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Ask the user to enter a number 3 | curr_value = int(input("Enter a number: ")) 4 | 5 | # Keep doubling until the value is 100 or more 6 | while curr_value < 100: 7 | curr_value = curr_value * 2 8 | print(curr_value) 9 | 10 | # This line is required to call the main() function 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/00_averages.py: -------------------------------------------------------------------------------- 1 | def average(a: float, b: float) -> float: 2 | """ 3 | Returns the average (mean) of two numbers a and b. 4 | """ 5 | return (a + b) / 2 6 | 7 | def main(): 8 | # Example calls to the average function 9 | avg_1 = average(0, 10) 10 | avg_2 = average(8, 10) 11 | 12 | # Calculating the final average of the two previous averages 13 | final = average(avg_1, avg_2) 14 | 15 | # Display results 16 | print("avg_1:", avg_1) 17 | print("avg_2:", avg_2) 18 | print("final:", final) 19 | 20 | # Required call to run main() 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/01_chaotic_counting.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | # Likelihood of stopping early (can be adjusted for more or less chaos) 4 | DONE_LIKELIHOOD = 0.3 5 | 6 | def done(): 7 | """ Returns True with a probability of DONE_LIKELIHOOD """ 8 | return random.random() < DONE_LIKELIHOOD 9 | 10 | def chaotic_counting(): 11 | for i in range(10): 12 | curr_num = i + 1 13 | if done(): 14 | return # Exit early if done() returns True 15 | print(curr_num) 16 | 17 | def main(): 18 | print("I'm going to count until 10 or until I feel like stopping, whichever comes first.") 19 | chaotic_counting() 20 | print("I'm done") 21 | 22 | # Run the main function 23 | if __name__ == '__main__': 24 | main() 25 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/02_count_even.py: -------------------------------------------------------------------------------- 1 | def count_even(lst): 2 | """ 3 | Prints the number of even numbers in the list. 4 | """ 5 | count = 0 6 | for num in lst: 7 | if num % 2 == 0: 8 | count += 1 9 | print(count) 10 | 11 | def get_list_of_ints(): 12 | """ 13 | Prompts the user to enter integers until they press enter. 14 | Returns a list of the entered integers. 15 | """ 16 | lst = [] 17 | user_input = input("Enter an integer or press enter to stop: ") 18 | while user_input != "": 19 | lst.append(int(user_input)) 20 | user_input = input("Enter an integer or press enter to stop: ") 21 | return lst 22 | 23 | def main(): 24 | lst = get_list_of_ints() 25 | count_even(lst) 26 | 27 | # This provided line is required to call the main() function. 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/04_double.py: -------------------------------------------------------------------------------- 1 | def double(num: int): 2 | return num * 2 3 | 4 | # There is no need to edit code beyond this point 5 | 6 | def main(): 7 | num = int(input("Enter a number: ")) 8 | num_times_2 = double(num) 9 | print("Double that is", num_times_2) 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/05_get_name.py: -------------------------------------------------------------------------------- 1 | def get_name(): 2 | # Prompt user to enter their name 3 | return input("Enter your name: ") 4 | 5 | # There is no need to edit code beyond this point 6 | 7 | def main(): 8 | name = get_name() 9 | print("Howdy", name, "! 🤠") 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/06_is_odd.py: -------------------------------------------------------------------------------- 1 | def is_odd(value: int): 2 | """ 3 | Checks to see if a value is odd. If it is, returns True. 4 | """ 5 | return value % 2 == 1 6 | 7 | def main(): 8 | for i in range(10, 20): 9 | if is_odd(i): 10 | print(f"{i} odd", end=" ") 11 | else: 12 | print(f"{i} even", end=" ") 13 | 14 | # There is no need to edit code beyond this point 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/07_print_divisor.py: -------------------------------------------------------------------------------- 1 | def print_divisors(num: int): 2 | print("Here are the divisors of", num) 3 | for i in range(1, num + 1): 4 | if num % i == 0: 5 | print(i, end=" ") # Print all on the same line with space 6 | 7 | def main(): 8 | num = int(input("Enter a number: ")) 9 | print_divisors(num) 10 | 11 | # There is no need to edit code beyond this point 12 | if __name__ == '__main__': 13 | main() 14 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/08_print_multiple.py: -------------------------------------------------------------------------------- 1 | def print_multiple(message: str, repeats: int): 2 | for _ in range(repeats): 3 | print(message) 4 | 5 | # There is no need to edit code beyond this point 6 | def main(): 7 | message = input("Please type a message: ") 8 | repeats = int(input("Enter a number of times to repeat your message: ")) 9 | print_multiple(message, repeats) 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/09_sentence_generator.py: -------------------------------------------------------------------------------- 1 | def make_sentence(word, part_of_speech): 2 | if part_of_speech == 0: 3 | # Noun case 4 | print(f"I am excited to add this {word} to my vast collection of them!") 5 | elif part_of_speech == 1: 6 | # Verb case 7 | print(f"It's so nice outside today it makes me want to {word}!") 8 | elif part_of_speech == 2: 9 | # Adjective case 10 | print(f"Looking out my window, the sky is big and {word}!") 11 | else: 12 | # Invalid input case 13 | print("Part of speech must be 0, 1, or 2! Can't make a sentence.") 14 | 15 | # This provided line is required at the end of 16 | # Python file to call the main() function. 17 | def main(): 18 | word = input("Please type a noun, verb, or adjective: ") 19 | print("Is this a noun, verb, or adjective?") 20 | part_of_speech = int(input("Type 0 for noun, 1 for verb, 2 for adjective: ")) 21 | make_sentence(word, part_of_speech) 22 | 23 | if __name__ == '__main__': 24 | main() 25 | -------------------------------------------------------------------------------- /Homework Projects/06_functions/10_print_ones_digit.py: -------------------------------------------------------------------------------- 1 | def print_ones_digit(num): 2 | print("The ones digit is", num % 10) 3 | 4 | def main(): 5 | num = int(input("Enter a number: ")) 6 | print_ones_digit(num) 7 | 8 | # This provided line is required at the end of 9 | # Python file to call the main() function. 10 | if __name__ == '__main__': 11 | main() 12 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/00_choosing_returns.py: -------------------------------------------------------------------------------- 1 | ADULT_AGE = 18 # U.S. age to be considered an adult 2 | 3 | def is_adult(age: int): 4 | if age >= ADULT_AGE: 5 | return True 6 | return False 7 | 8 | ########## No need to edit code beyond this point :) ########## 9 | 10 | def main(): 11 | age = int(input("How old is this person?: ")) # Prompt for the person's age 12 | print(is_adult(age)) # Print the result of is_adult 13 | 14 | if __name__ == "__main__": 15 | main() 16 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/01_greetings.py: -------------------------------------------------------------------------------- 1 | def greet(name): 2 | return "Greetings " + name + "!" 3 | 4 | def main(): 5 | name = input("What's your name? ") # Get the user's name 6 | print(greet(name)) # Call greet function and print the result 7 | 8 | if __name__ == '__main__': 9 | main() 10 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/02_in_range.py: -------------------------------------------------------------------------------- 1 | def in_range(n, low, high): 2 | """ 3 | Returns True if n is between low and high, inclusive. 4 | high is guaranteed to be greater than low. 5 | """ 6 | if low <= n <= high: 7 | return True 8 | return False 9 | 10 | def main(): 11 | n = int(input("Enter a number: ")) 12 | low = int(input("Enter the lower bound: ")) 13 | high = int(input("Enter the upper bound: ")) 14 | 15 | # Call the in_range function and print the result 16 | print(in_range(n, low, high)) 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/03_in_stock.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Prompt the user to enter a fruit 3 | fruit = input("Enter a fruit: ") 4 | 5 | # Get the number of fruit in stock 6 | stock = num_in_stock(fruit) 7 | 8 | # Check if the fruit is in stock and print the result 9 | if stock == 0: 10 | print("This fruit is not in stock.") 11 | else: 12 | print("This fruit is in stock! Here is how many:") 13 | print(stock) 14 | 15 | def num_in_stock(fruit): 16 | """ 17 | This function returns the number of fruit Sophia has in stock. 18 | """ 19 | if fruit.lower() == 'apple': 20 | return 2 21 | if fruit.lower() == 'durian': 22 | return 4 23 | if fruit.lower() == 'pear': 24 | return 1000 25 | else: 26 | # this fruit is not in stock. 27 | return 0 28 | 29 | # Run the main function 30 | if __name__ == '__main__': 31 | main() 32 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/04_multiple_returns.py: -------------------------------------------------------------------------------- 1 | def get_user_info(): 2 | # Asking for user information and storing the input in variables 3 | first_name = input("What is your first name?: ") 4 | last_name = input("What is your last name?: ") 5 | email_address = input("What is your email address?: ") 6 | 7 | # Returning the user data as a tuple 8 | return first_name, last_name, email_address 9 | 10 | # Main function to execute the program 11 | def main(): 12 | # Calling the get_user_info function and storing the returned data 13 | user_data = get_user_info() 14 | 15 | # Printing the received user data 16 | print("Received the following user data:", user_data) 17 | 18 | # Running the main function 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /Homework Projects/07_information_flow/05_subtract_7.py: -------------------------------------------------------------------------------- 1 | def subtract_seven(num): 2 | # Subtract 7 from the given number 3 | num = num - 7 4 | return num 5 | 6 | def main(): 7 | # Initial number to subtract 7 from 8 | num = 7 9 | 10 | # Calling the subtract_seven function and updating the num variable 11 | num = subtract_seven(num) 12 | 13 | # Printing the result 14 | print("this should be zero:", num) 15 | 16 | # Ensure the main function runs when the script is executed 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Online Class Projects/01_basics/00_joke_bot.py: -------------------------------------------------------------------------------- 1 | # Constants for user prompts and messages 2 | PROMPT: str = "What do you want? " 3 | JOKE: str = ( 4 | "Here is a joke for you! Sophia is heading out to the grocery store. " 5 | "A programmer tells her: get a liter of milk, and if they have eggs, get 12. " 6 | "Sophia returns with 13 liters of milk. The programmer asks why and Sophia replies: " 7 | "'because they had eggs'" 8 | ) 9 | SORRY: str = "Sorry, I only tell jokes." 10 | 11 | def main(): 12 | # Prompting the user for input 13 | user_input = input(PROMPT).strip().lower() # Taking input and cleaning it 14 | 15 | # Conditional check to print the joke or sorry message 16 | if user_input == "joke": 17 | print(JOKE) 18 | else: 19 | print(SORRY) 20 | 21 | # Ensuring the program runs only when executed directly 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /Online Class Projects/01_basics/01_double_it.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Asking the user for an initial number 3 | curr_value = int(input("Enter a number: ")) # Converting the input to an integer 4 | 5 | # Loop to double the value until it reaches or exceeds 100 6 | while curr_value < 100: 7 | # Doubling the current value 8 | curr_value = curr_value * 2 9 | # Printing the updated value 10 | print(curr_value, end=" ") 11 | 12 | # Ensuring that the main function is executed when the script is run directly 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /Online Class Projects/01_basics/02_liftoff.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | # Countdown from 10 to 1 and print each number 3 | for i in range(10, 0, -1): 4 | print(i, end=" ") # Print the countdown number, followed by a space 5 | 6 | # After the countdown, print 'Liftoff!' 7 | print("Liftoff!") 8 | 9 | # Ensuring that the main function is executed when the script is run directly 10 | if __name__ == "__main__": 11 | main() 12 | -------------------------------------------------------------------------------- /Online Class Projects/01_basics/03_guess_my_number.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def main(): 4 | # Generate the secret number at random 5 | secret_number: int = random.randint(1, 99) 6 | 7 | print("I am thinking of a number between 1 and 99...") 8 | 9 | # Get the user's first guess 10 | guess = int(input("Enter a guess: ")) 11 | 12 | # Loop until the user guesses the secret number 13 | while guess != secret_number: 14 | if guess < secret_number: 15 | print("Your guess is too low") 16 | else: 17 | print("Your guess is too high") 18 | 19 | print() # Print an empty line to tidy up the console for new guesses 20 | 21 | # Get a new guess from the user 22 | guess = int(input("Enter a new guess: ")) 23 | 24 | print(f"Congrats! The number was: {secret_number}") 25 | 26 | # Ensure the main function is executed when the script is run directly 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /Online Class Projects/01_basics/04_random_numbers.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | # Constants defining the number of random numbers, and their range 4 | N_NUMBERS: int = 10 5 | MIN_VALUE: int = 1 6 | MAX_VALUE: int = 100 7 | 8 | def main(): 9 | # Generate and print 10 random numbers between 1 and 100 10 | for _ in range(N_NUMBERS): 11 | print(random.randint(MIN_VALUE, MAX_VALUE), end=" ") 12 | 13 | # Ensure the main function is executed when the script is run directly 14 | if __name__ == '__main__': 15 | main() 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Python Projects](/favicon.ico) [![Typing SVG](https://readme-typing-svg.demolab.com?font=Roboto+Slab&weight=500&size=27&duration=4000&pause=500&color=ffde7b¢er=true&vCenter=true&width=700&height=50&lines=%E2%9C%A8Hey%2C+I'm+Rida+Naz%E2%9C%A8;%E2%9C%A8Full+Stack+Developer+%7C+AI+Engineer%E2%9C%A8;%E2%9C%A8Building+Scalable+Web+Apps+%26+AI+Solutions%E2%9C%A8)](https://git.io/typing-svg) 2 | 3 |

4 | ridanaz 5 |

6 | 7 | # Google Colab 8 | 9 | **Google Colab** (Colaboratory) is a **cloud-based Jupyter notebook environment** that allows you to write and execute Python code in your browser. It provides free access to **GPUs** and **TPUs**, supports **Google Drive** integration, and is commonly used for ***Machine Learning, Data Science, and AI Development*** without needing local setup. 10 | 11 | [https://colab.research.google.com/](https://colab.research.google.com/) 12 | 13 | 14 | ## Python Homework Projects [->>](/Homework%20Projects/) 15 | 16 | ## Online Class Projects 17 | 18 | ## Compulsory Project 19 | 20 | 21 | ## 🔗 Links 22 | [![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ridanaz.vercel.app/) 23 | [![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://linkedin.com/in/ridanaz67) 24 | [![gmail](https://img.shields.io/badge/gmail-f44336?style=for-the-badge&logo=twitter&logoColor=white)](mailto:rnaz3414@gmail.com) 25 | [![medium](https://img.shields.io/badge/medium-white?style=for-the-badge&logo=twitter&logoColor=black)](https://medium.com/@rnaz3414) -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RidaNaz/Python-Projects/51efcb121217f2b72a6c994934b8a65fe5f03b54/favicon.ico --------------------------------------------------------------------------------