top of page

Forum Comments

1/8 Week 15 Review Homework
In Introduction to Python
jiangchristopher66
Jan 13, 2023
number = input("Part 1: Please input a number to ordinalize (from one to one hundred): ").lower() irregNumbers = {"one":"first", "two":"second", "three":"third", "five":"fifth", "twelve":"twelfth", "eight":"eighth", "nine":"ninth"} div10 = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"} if number in irregNumbers.keys(): print(f"The associated ordinal number is {irregNumbers.get(number)}") elif number in div10: print(f"The associated ordinal number is {number[:-1]}ieth") else: try: if number.split("-")[1] in irregNumbers.keys(): print(f"The associated ordinal number is {number.split('-')[0]}-{irregNumbers.get(number.split('-')[1])}") except IndexError: print(f"The associated ordinal number is {number}th") numbered = False while numbered == False: num2 = input("\n\nPart 2: Please input characters to check for numberness: ") try: print(f"{float(num2)} is a number!") numbered = True except ValueError: print("That's not a number.") print("\nPart 3: ") table = [] def addrow(col1, col2): table.append([col1, col2]) addrow("App", "Number of hours") addrow("Discord", "5") addrow("Safari", "4.5") addrow("Messages", "1.25") for list in table: print(list[0], list[1], sep = "\t") import random choices = ("rock", "paper", "scissors") def rps(): choice = input("\n\nPart 4: Let's play rock, paper, scissors! Rock, paper, scissors, shoot... ").lower() comp = random.choice(choices) if choice in choices: if comp == choice: print("We drew...") elif comp == "rock": if choice == "paper": print(f"You won! {choice} beats {comp}.") else: print(f"You lost. {comp} beats {choice}.") elif comp == "paper": if choice == "rock": print(f"You lost. {comp} beats {choice}.") else: print(f"You won! {choice} beats {comp}.") else: if choice == "rock": print(f"You won! {choice} beats {comp}.") else: print(f"You lost. {comp} beats {choice}.") else: print("Please enter a valid choice.") again = input("Want to play again? ") if again.lower() == "yes": rps() rps() with open("temp.txt", "w+") as f: f.writelines(["three\n", "new\n", "lines!!!\n\n"]) f.seek(0) print("\n\nPart 5: " + f.read())
0
0
12/18 - Homework Week 14
In Introduction to Python
10/30 - Homework Week 8
In Introduction to Python
jiangchristopher66
Nov 06, 2022
import random grid = [] for i in range(4): row = [] for j in range(4): row.append(random.uniform(10, 20)) grid.append(row) for k in range(4): for l in range(4): print(grid[k][l], end = " ") print() grid = [] for k in range(10): row = [] for l in range(10): row.append(0) grid.append(row) def printGrid(grid): print("\t", end="") for m in range(10): print(m, end=" ") print("\n") rowNum = 0 for list in grid: print(str(rowNum), end="\t") for num in list: print(num, end=" ") print() rowNum += 1 printGrid(grid) turns = 10 chests = [] for n in range(3): coords = [random.randint(0, 9), random.randint(0, 9)] while coords in chests: for o in range(2): coords.append(random.randint(0, 9)) chests.append(coords) print(chests) chestFound = 0 pastGuesses = [] while turns > 0: guess = "" while guess == "" or guess in pastGuesses: guess = input("Make a guess, in format of x, y please: ").split(", ") for i in range(2): guess[i] = int(guess[i]) if guess in pastGuesses: print("Duplicate guess, try again") pastGuesses.append(guess) turns -= 1 if guess in chests: input("You found a chest! Congratulations!! :D Press any key to continue ") chestFound += 1 grid[guess[1]][guess[0]] = "!" else: chestDistance = [] for chest in chests: distance = ((chest[0] - guess[0])**2 + (chest[1] - guess[1])**2)**(1/2) chestDistance.append(distance) smallestDistance = int(min(chestDistance) + 0.5) grid[guess[1]][guess[0]] = smallestDistance printGrid(grid) if chestFound == 3: print("You found all the chests!! BD") break if turns == 0: print("You ran out of turns. You lost D:") print("Locations of the chests:") for chest in chests: print(chest)
0
0
9/25 - Homework Week 3
In Introduction to Python
jiangchristopher66
Sep 30, 2022
print(''' Sorry in advance for the wall of text... Please direct all blame to LoL Homework Creators & Co. and not Chris.\n\n Did you know? 1. a. '"i can" > "CODE"' and '"i can" != "CODE"' and '"i can" >= "CODE"' are all true? b. 'float(True) // 7 == 0.0' and 'float(True) // 7 <= 0.0' and 'float(True) // 7 >= 0.0' are all true as well? c. Guess what? '"yEET" > "y e e t"' and '"yEET" >= "y e e t"' and '"yEET" != "y e e t"' are all... TRUE! woah. never expected that, did you?\n 2. a. The monstrosity known as '(6.3 + 7.2 / 2 == (6.3 + 7.2) / 2) OR NOT(2 * int(7.4) > 14)' is True if you count the "OR NOT" as lowercase letters. If not, you'll get an error message. b. '(“mat ” > “mate”) != (“for” > “Forward”) AND (7 > 8) != (9 > 6)' is True, again counting the "AND" as lowercase.\n 3. ''') grade = input("What's your grade (as a percentage)? ") try: grade = int(grade) if grade > 100: print("WOOOOAAAAAAAH!!! YOU'RE AMAAAAAAAAAAAAAAAZING") elif grade < 100 and grade > 90: print("A A ayyy!") elif grade < 90 and grade > 80: print("B. Better be better bud.") elif grade <= 80 and grade >= 70: print("C for crap.") elif grade < 70 and grade >= 60: print("Dang, Ds don't delight.,,") elif grade < 60: print("f in chat for failing friends") elif grade == 90 or grade == 100: print("Somehow LoL Homework Creators & Co. forgot about 90 and 100... Not nice, LHC&C...") except: print("bruh just enter an integer please make my life easy.")
0
0

jiangchristopher66

More actions
bottom of page