CodeHS Unit 7 Python Exam Solutions, Exams of Computer Science

Verified solutions to the codehs unit 7 python exam. It includes code snippets and explanations for various programming exercises, covering topics such as tuples, functions, lists, and string manipulation. It serves as a valuable resource for students learning python and preparing for similar coding assessments. The solutions are designed to help students understand the underlying concepts and improve their problem-solving skills in python programming. A range of topics, including tuple manipulation, function definitions, list operations, and string processing. Each solution is accompanied by a code snippet and a brief explanation of the logic behind it. This resource is particularly useful for students who are looking for practice problems and solutions to reinforce their understanding of python programming concepts.

Typology: Exams

2025/2026

Available from 09/25/2025

ScrubLifeDiaries
ScrubLifeDiaries 🇺🇸

5

(3)

7.5K documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
P a g e | 1
CODEHS UNIT 7 PYTHON EXAM
UPDATED EXAM WITH VERIFIED
SOLUTIONS.
7.1.7 Fix This Tuple - correct answer -my_tuple = (0, 1, 2, "hi", 4,
5)
# Your code here...
my_tuple = my_tuple[:3] + (3,) + my_tuple[4:]
print(my_tuple)
7.1.8: Citation - correct answer -def citation(names):
author_name = ((names))
name = str(names[2]) + ", " + str(names[0]) + " " + str(names[1])
return name
print(citation(["Martin", "Luther", "King, Jr."]))
7.1.9: Diving Contest - correct answer -# fill in this function to
return the total of the three judges' scores!
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download CodeHS Unit 7 Python Exam Solutions and more Exams Computer Science in PDF only on Docsity!

CODEHS UNIT 7 PYTHON EXAM

UPDATED EXAM WITH VERIFIED

SOLUTIONS.

7.1.7 Fix This Tuple - correct answer - my_tuple = (0, 1, 2, "hi", 4,

Your code here...

my_tuple = my_tuple[:3] + (3,) + my_tuple[4:] print(my_tuple) 7.1.8: Citation - correct answer - def citation(names): author_name = ((names)) name = str(names[2]) + ", " + str(names[0]) + " " + str(names[1]) return name print(citation(["Martin", "Luther", "King, Jr."])) 7.1.9: Diving Contest - correct answer - # fill in this function to return the total of the three judges' scores!

judges_scores=(10,10,10) def calculate_score(judges_scores): return judges_scores[0]+judges_scores[1]+judges_scores[2] print (calculate_score(judges_scores)) 7.1.10: Coordinate Pairs - correct answer - import math

fill in this function to return the distance between the two points!

first_point = (1, 1) second_point = (4, 5) def distance(first_point, second_point): x1= first_point[0] x2= second_point[0] y1= first_point[1] y2= second_point[1] power1 = pow(y2 - y1, 2) power2 = pow(x2 - x1, 2) return math.sqrt (power1 + power2)

print (greeting(user_info)) 7.2.9 Top Movies - correct answer - # Enter your code here movie_list = ["John Wick 3", "Angry Birds Movie", "Rush Hour 2", "Ip Man"] print(movie_list[0]) movie_list[0] = "Star Wars" print(movie_list[0]) 7.3.6: Max In List - correct answer - # your function should return the maximum value in my_list def max_int_in_list(my_list): return 0 my_list = [1, 3, 456, 2038] def max_int_in_list(my_list): highest = my_list[-1] for num in my_list: if num > highest:

highest = num return highest biggest_int = max_int_in_list(my_list) print (biggest_int) 7.3.7: Owls - correct answer - # this function should return the number of words that contain "owl"! def owl_count(text): return 0 text ="I really like owls. Did you know that an owl's eyes are more than twice as big as the eyes of other birds of comparable weight? And that when an owl partially closes its eyes during the day, it is just blocking out light? Sometimes I wish I could be an owl." word ="owl" def owl_count(text): text=text.lower()

7.3.9 Word Ladder - correct answer - user_string = input("Enter a string: ") def get_index(): while True: try: user_index = int(input("Enter an Index: ")) if user_index >= len(user_string): print("Invalid Index") continue if user_index < - 1: print("Invalid Index") continue except ValueError: print("Invalid Index") continue return user_index def get_string(): while True: user_letter = input("Enter letter: ") if user_letter.isupper(): print("Character must be a lowercase letter!") continue

if len(user_letter) > 1: print("Must be exactly one character!") continue return user_letter while True: user_string = list(user_string) returned_index = get_index() if returned_index == - 1: break returned_string = get_string() user_string[returned_index] = returned_string print("".join(user_string)) 7.4.4 How Many Names? - correct answer - nn = int(input("How many names do you have?:")) namelist = [] for i in range (nn): name = input("Name:") namelist.append(name)

list.append(name) list.sort() print(list) 7.4.12 Empty List (Append and Remove) - correct answer - my_list = [] my_list.append(3) my_list.append("hello") my_list.append(False) for x in my_list: print(x) my_list.remove(3) my_list.remove(False) print(my_list)

7.4.13: Take a Thing Out, Sort It, and Reverse It - correct answer

  • my_list=["eggplant", "apple", "zucchini", "rambutan", "grapefruit"] def remove_sort_reverse(my_list): my_list.remove("eggplant") my_list.sort() my_list.reverse() return my_list print (remove_sort_reverse(my_list)) 7.4.14 Librarian, Part 2 - correct answer - list=[] for i in range (5): name = input("Name: ") list.append(name.split()[-1]) list.sort() print(list)

if (flip == 0): result = "Heads" else: result = "Tails" return result for n in range(N): result = coin_flip() if result == "Heads": epsilon[n] = 1 else: epsilon[n] = - 1 print(epsilon) coin_flip() print(result)