7. The GAME#

Solve the problems below, each problem solved gets a guess at a letter.

To get credit, you must write a few test cases (a convincing amount) to show your function works as intended. You should only use tools introduced in class (no built-in functions that accomplish the goal).

Problems are categorized by difficulty: I, II, III. Those with coding experience should not do level-I problems.

7.1. Level I#

1.1

Write the functions F_to_C() and C_to_F() to convert Fahrenheit to Celsius and vice versa.

The equation for conversion from F to C is: \( C = 5*(F-32)/9\)

1.2

Write the function factorize() that takes as input a positive integer and returns all the integer factors of that number. If the number is prime, also print “That’s a prime number!”

1.3

Write the function check_cyclic_equality() that takes two lists and checks if there is a rotation that makes them same.

A rotation/cycling of 1 is defined as taking the zero-th element of the list and moving it to the end. For example, [‘dog’, 7, ‘chicken’, ‘rabbit’, 9] cycled by 2 would be [‘chicken’, ‘rabbit’, 9, ‘dog’, 7].

If the lists are cyclically equal, return the number the second list has to be cycled to equal the first list. If not, return False.

7.2. Level II#

2.1

Write the function odd_even_counter() that takes a list of integers. If there are more odds than evens, print ‘odds win’. If there are more evens than odds, print ‘evens win’. If there are the same number, print “it’s a tie!”.

2.2

Write the function group_by_first that takes a list of numbers and splits them into groups (lists) based on their first digit. For example:

group_by_first([80, 9, 8, 107, 65, 601, 1009, 600019])

would return:

[80, 8], [9], [107, 1009], [65, 601, 600019]

2.3

Write the game hot_cold(). The game generates a random number between 0-100 (using randint demonstrated below). The user gets 10 guesses at the number. They should get the following clues:

  • ‘burning hot’ if within 3

  • ‘hot’ if within 10

  • ‘warm’ if within 20

  • ‘cold’ if more than 20 away

If the user guesses correctly, congratulate them and tell them how many guesses it took for them to win! If they run out of guesses, tell them they lost, reveal the secret number, and encourage them to play again.

from random import randint

secret_number = randint(0, 100)
secret_number
3

7.3. Level III#

3.1

Write the function make_sublists() that takes as input a list and returns as output a list of lists containing every unique sublist made with items from the original list (order matters).

Even if the original list includes duplicate entries, the list-of-lists should not have duplicates. For example:

make_groupings([1,2,1]) should return:

[[1], [2], [1,1], [1,2], [2,1], [1,1,2], [1,2,1], [2,1,1]]

3.2

Write wordle_tm(). You know the game. Code it. It won’t look pretty, but should play with all the same rules.

I’ve provided the complete wordle wordlist below.

import requests
from random import randint

wordle_wordlist = requests.get('https://raw.githubusercontent.com/tabatkins/wordle-list/refs/heads/main/words').text.split('\n')

3.3

Write the function word_counter() that takes as input a passage of text and returns as output a list of lists. Each sublist should contain a unique word and the number of times it occurs in the passage.

Use lists, not dictionaries.

# test text
Romeo = 'But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun. Arise, fair sun, and kill the envious moon, Who is already sick and pale with grief, That thou her maid art far more fair than she. It is my lady, O, it is my love! O, that she knew she were! She speaks, yet she says nothing: what of that?'
TheCat = 'We looked and we saw him! The Cat in the Hat! and he said to us, "Why do you sit there like that?" "I know it is wet and the sun is not sunny. But we can have lots of good fun that is funny!"'