The instructions for the coding test are as follows:" Votee would like to conduct the…
- User
The instructions for the coding test are as follows:"
Votee would like to conduct the coding test in a recorded live session. The idea is to connect to an API that plays a Wordle-like puzzle. You can find the API documentation at the following link: https://wordle.votee.dev:8000/redoc
Developers are allowed to use any frameworks, IDEs, chatbots, LLMs, or other resources to write their program and showcase their skill set. However, if you take references from other open-source projects or tutorials, please ensure that proper credit is given. Plagiarism will not be tolerated, and it may affect the evaluation of your application.
Your task is to write a program that automatically guesses random words against the API, using the following command as an example: curl -v ‘https://wordle.votee.dev:8000/random?guess=theft&seed=1234'" If I run curl -v ‘https://wordle.votee.dev:8000/random?guess=theft&seed=1234 in the terminal, the output: StatusCode : 200 StatusDescription : OK Content : [{"slot":0,"guess":"t","result":"correct"},{"slot":1,"guess":"h","result":"correct"},{"slot":2,"guess":"e","result":"correct"}, {"slot":3,"guess":"f","result":"correct"},{"slot":4,"guess":"t","result":... RawContent : HTTP/1.1 200 OK Content-Length: 211 Content-Type: application/json Date: Sun, 26 May 2024 08:27:33 GMT Server: uvicorn
[{"slot":0,"guess":"t","result":"correct"},{"slot":1,"guess":"h","result":...Forms : {} Headers : {[Content-Length, 211], [Content-Type, application/json], [Date, Sun, 26 May 2024 08:27:33 GMT], [Server, uvicorn]} Images : {} InputFields : {} Links : {} ParsedHtml : mshtml.HTMLDocumentClass RawContentLength : 211
My Python program that guess the words: "import random import requests import json
Load the word list from a file.
with open("C:/Users/a/Desktop/wordle/valid-wordle-words.txt", 'r') as file: word_list = [line.strip() for line in file.readlines()]
API base URL
base_url = 'https://wordle.votee.dev:8000/random'
Function to make a guess by calling the API.
def make_guess(guess, seed): response = requests.get(f"{base_url}?guess={guess}&seed={seed}") if response.status_code == 200: # Check if the response status code is 200 (OK) return response.json() # Return the JSON response else: print("Failed to call the api.") return None # Return None if the request was not successful
- Assistant
- User
"Traceback (most recent call last): File "C:\Users\a\AppData\Local\Programs\Python\Python312\Lib\statistics.py", line 327, in _exact_ratio return (x.numerator, x.denominator) ^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'numerator'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\a\Desktop\python\pythonProject1\main.py", line 140, in test_multiple_seeds(10) File "C:\Users\a\Desktop\python\pythonProject1\main.py", line 134, in test_multiple_seeds mean_case = mean(attempts_list) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\a\AppData\Local\Programs\Python\Python312\Lib\statistics.py", line 484, in mean T, total, n = _sum(data) ^^^^^^^^^^ File "C:\Users\a\AppData\Local\Programs\Python\Python312\Lib\statistics.py", line 193, in _sum for n, d in map(_exact_ratio, values): File "C:\Users\a\AppData\Local\Programs\Python\Python312\Lib\statistics.py", line 330, in _exact_ratio raise TypeError(msg) TypeError: can't convert type 'str' to numerator/denominator" Fix this error by just modifying the test_multiple_seeds() only.
- Assistant
The error appears to be caused by the fact that some elements in the
attempts_listare strings instead of integers. This happens ifsolve_puzzlereturns a string instead of a number for the number of attempts. To ensure thatattempts_listonly contains integers, we can explicitly convert the number of attempts to an integer before adding it to the list.We need to update the
test_multiple_seedsfunction to handle this properly.Here is the modified function: