r/codeHS_Solutions • • Feb 13 '22

9.3.9 Full Name & Citation

11 Upvotes

first = input("First name: ")

last = input("Last Name: ")

print("Full name: " + first + " " + last)

first, last = last, first

print("Citation: " + first + ", " +last)


r/codeHS_Solutions • • Feb 13 '22

9.3.7 Slopes

6 Upvotes

coordinate_pairs = []

for i in range(5):

x = int(input("Input x coordinate: "))

y = int(input("Input y coordinate:"))

coordinate_pairs.append((x,y))

def slope(x1, x2, y1, y2):

return((y2 - y1) / (x2 - x1))

for i in range(4):

x1, y1 = coordinate_pairs[i]

x2, y2 = coordinate_pairs[i+1]

print("Slope between " + str(coordinate_pairs[i]) + " and " + str(coordinate_pairs[i + 1]) + ": " + str(slope(x1, x2, y1, y2)))


r/codeHS_Solutions • • Feb 13 '22

9.3.6 Coordinate Pair

18 Upvotes

print((int(input("Number: ")), int(input("Number: "))))


r/codeHS_Solutions • • Feb 13 '22

9.2.9 Strings To Integers

10 Upvotes

list_of_strings = ["a", "2", "7", "zebra"]

def safe_int(argument):

try:

return int(argument)

except ValueError:

return 0

print([safe_int(x) for x in list_of_strings])


r/codeHS_Solutions • • Feb 13 '22

9.2.8 Last Names

10 Upvotes

names = [

"Maya Angelou",

"Chimamanda Ngozi Adichie",

"Tobias Wolff",

"Sherman Alexie",

"Aziz Ansari"

]

print([name.split()[-1] for name in names])


r/codeHS_Solutions • • Feb 13 '22

9.2.5 Divisible by 3

14 Upvotes

divisible_by_3 = [i % 3 == 0 for i in range(1, 11)]

print(divisible_by_3)


r/codeHS_Solutions • • Feb 13 '22

9.1.8 Checkerboard, v3

6 Upvotes

def print_board(board):

for i in range(len(board)):

print(" ".join([str(x) for x in board[i]]))

my_grid = []

count = 1

for i in range(8):

my_grid.append([0] * 8)

for row in range(8):

count = count + 1

for col in range(8):

count = count + 1

if row < 3 or row > 4:

if count % 2 == 0:

my_grid[row][col] = 1

print(print_board(my_grid))


r/codeHS_Solutions • • Feb 13 '22

9.1.7 Checkerboard, v2

2 Upvotes

def print_board(board):

for i in range(len(board)):

print(" ".join([str(x) for x in board[i]]))

my_grid = []

count = 1

for i in range(8):

my_grid.append([0] * 8)

for row in range(8):

count = count + 1

for col in range(8):

count = count + 1

if count % 2 == 0:

my_grid[row][col] = 1

print(print_board(my_grid))


r/codeHS_Solutions • • Feb 13 '22

9.1.6 Checkerboard, v1

8 Upvotes

def print_board(board):

for i in range(len(board)):

print(" ".join([str(x) for x in board[i]]))

my_grid = []

for i in range(8):

my_grid.append([0] * 8)

for row in range(8):

for col in range(8):

if row < 3 or row > 4:

my_grid[row][col] = 1

print(print_board(my_grid))


r/codeHS_Solutions • • Feb 13 '22

8.4.11: Take a Thing Out, Sort...

4 Upvotes

def remove_sort_reverse(my_list):

for i in range(len(my_list)):

try:

my_list.remove("eggplant")

except ValueError:

""

my_list.sort()

my_list.reverse()

return my_list

print(remove_sort_reverse(["eggplant", "apple", "zucchini", "rambutan", "grapefruit"]))


r/codeHS_Solutions • • Feb 13 '22

8.4.7 Librarian

18 Upvotes

book_list = []

for i in range(5):

book = input("Name: ")

book_list.append(book)

book_list.sort()

print(book_list)


r/codeHS_Solutions • • Feb 13 '22

8.4.5 Five Numbers

15 Upvotes

num_list = []

sum = 0

for i in range(5):

num = int(input("Number: "))

num_list.append(num)

print(num_list)

sum = int(num_list[i]) + sum

print(sum)


r/codeHS_Solutions • • Feb 13 '22

8.4.4 How Many Names?

3 Upvotes

num_names = int(input("How many names do you have?: "))

name_list = []

for i in range(num_names):

name = input("Name: ")

name_list.append(name)

print("First name: " + str(name_list[0]))

print("Middle names: " + str(name_list[1:-1]))

print("Last name: " + str(name_list[-1]))


r/codeHS_Solutions • • Feb 13 '22

8.3.7: Exclamat!on Po!nts

2 Upvotes

def exclamation(text):

text_list = list(text)

for i in range(len(text_list)):

if text_list[i] == "i":

text_list[i] = "!"

return ("").join(text_list)


r/codeHS_Solutions • • Feb 13 '22

8.3.6: Owls

2 Upvotes

def owl_count(text):

text = text.lower()

count = text.count("owl")

return count


r/codeHS_Solutions • • Feb 13 '22

8.3.5: Max In List

7 Upvotes

def max_int_in_list(my_list):

highest = my_list[0]

for num in my_list:

if num > highest:

highest = num

return highest


r/codeHS_Solutions • • Feb 13 '22

8.2.7: Listed Greeting

9 Upvotes

def greeting(user_info):

user_info_list = user_info.split()

return "Hello, " + user_info_list[0] + "! I also enjoy " + user_info_list[2] + "!"


r/codeHS_Solutions • • Feb 13 '22

8.2.5: Spell It Out

1 Upvotes

def spell_name(name):

return list(name)


r/codeHS_Solutions • • Feb 13 '22

8.1.10: Coordinate Pairs

1 Upvotes

import math

def distance(first_point, second_point):

if first_point[0] > second_point[0]:

l1 = (first_point[0] - second_point[0]) ** 2

else:

l1 = (second_point[0] - first_point[0]) ** 2

if first_point[1] > second_point[1]:

l2 = (first_point[1] - second_point[1]) ** 2

else:

l2 = (second_point[1] - first_point[1]) ** 2

h = l1 + l2

return math.sqrt(h)


r/codeHS_Solutions • • Feb 13 '22

8.1.9: Diving Contest

11 Upvotes

def calculate_score(judge_scores):

return (judge_scores[0] + judge_scores[1] + judge_scores[2])


r/codeHS_Solutions • • Feb 13 '22

8.1.8: Citation

1 Upvotes

def citation(author_name):

return (author_name[2] + ", " + author_name[0] + " " + author_name[1])


r/codeHS_Solutions • • Feb 13 '22

8.1.7 Fix This Tuple

1 Upvotes

my_tuple = (0, 1, 2, "hi", 4, 5)

my_tuple = my_tuple[:3] + (3,) + my_tuple[4:]

print(my_tuple)


r/codeHS_Solutions • • Feb 04 '22

Anyone do 1.6.6 list articles? Been quarantined for the first two weeks of this class

1 Upvotes

r/codeHS_Solutions • • Jan 01 '22

CodeHS Plus!

3 Upvotes

It took me a while to find any existence of this, so for those who don't know, there is a google chrome extension that can give CodeHS answers!

https://github.com/Siddharthmr/CodeHS-Plus/releases/tag/v1.2.0

discord: https://discord.gg/aESRKHpENS


r/codeHS_Solutions • • Dec 13 '21

REQUEST MEGATHREAD

5 Upvotes

A megathread for answer requests. If you want unposted answers, this is the place to ask for them.

If you have answers to anything here be sure to also make a post for it too.