My code is not running at all on the console. It only installs python and numpy and stops there. It doesn’t further run the main code after that, even after refreshing the page and running it again. Please, what can I do to speed up the code running on the ide.
send a link to the repl or a minimal repl which reproduces the issue
https://replit.com/@SerLette/boilerplate-mean-variance-standard-deviation-calculator#mean_var_std.py
numpy takes quite a while to update, so try doing this:
- press the three dots
- press the show hidden files
- go to line 91, or
guessImports = true
and change it toguessImports = false
- change
mean_var_std.py
to this:
import numpy as np
def calculate(input):
if len(input) != 9:
raise ValueError("List must contain nine numbers")
print(input)
a = np.array(input).reshape(3, 3)
#print(a)
cal = {}
cal['mean'] = [a.mean(0).tolist(), a.mean(1).tolist(), a.mean()],
cal['variance'] = [a.var(0).tolist(), a.var(1).tolist(), a.var()],
cal['standard deviation'] = [a.std(0).tolist(), a.std(1).tolist(), a.std()],
cal['max'] = [a.max(0).tolist(), a.max(1).tolist(), a.max()],
cal['min'] = [a.min(0).tolist(), a.min(1).tolist(), a.min()],
cal['sum'] = [a.sum(0).tolist(), a.sum(1).tolist(), a.sum()]
return cal
yes that’s because cal = dict
not cal = {}
that’s the main problem i’m having. it takes a long time to update and then takes another whole session to run, which most times doesn’t end up running
I can’t find the guessImports = false place or the line 91 under show hidden files
I am still receiving AssertionError, though it’s running faster now. but it seems to have difficulty running my exception, maybe because it’s failing to install numpy package.
change mean_var_std.py
to:
import numpy as np
def calculate(input):
print(input)
a = np.array(input).reshape(3, 3)
#print(a)
cal = {}
cal['mean'] = [a.mean(0).tolist(), a.mean(1).tolist(), a.mean()],
cal['variance'] = [a.var(0).tolist(), a.var(1).tolist(), a.var()],
cal['standard deviation'] = [a.std(0).tolist(), a.std(1).tolist(), a.std()],
cal['max'] = [a.max(0).tolist(), a.max(1).tolist(), a.max()],
cal['min'] = [a.min(0).tolist(), a.min(1).tolist(), a.min()],
cal['sum'] = [a.sum(0).tolist(), a.sum(1).tolist(), a.sum()]
return cal
It’s meant to raise a ValueError (“List must contain nine numbers”) if the list is not up to, or more than 9 numbers
Thanks a lot. I have finally changed the dict code to truncated brackets, after assigning it as type dict.
thanks for the help bro. It has passed the 3 tests
Bro, I’m having same or rather worse problem as before with my present project.
https://replit.com/@SerLette/boilerplate-demographic-data-analyzer#demographic_data_analyzer.py
Running a code on my replit console is near impossible. It is so slow that it doesn’t complete installing of modules, talk more of running the actual python code. It was earlier suggested to turn guessImports = false
, but it rather doesn’t import the pandas module I need to run my program.
Above is my project and I can’t test run it for errors while writing the codes. What should I do?
The Following is not error free but will run
Change the .replit
file to:
# The command that runs the program. If the interpreter field is set, it will have priority and this run command will do nothing
run = "python3 main.py"
# The primary language of the repl. There can be others, though!
language = "python3"
entrypoint = "main.py"
# A list of globs that specify which files and directories should
# be hidden in the workspace.
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]
# Specifies which nix channel to use when building the environment.
[nix]
channel = "stable-22_11"
# The command to start the interpreter.
[interpreter]
[interpreter.command]
args = [
"stderred",
"--",
"prybar-python310",
"-q",
"--ps1",
"\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
"-i",
]
env = { LD_LIBRARY_PATH = "$PYTHON_LD_LIBRARY_PATH" }
[env]
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH = "${VIRTUAL_ENV}/lib/python3.10/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "${HOME}/${REPL_SLUG}/.cache/pypoetry"
# Enable unit tests. This is only supported for a few languages.
[unitTest]
language = "python3"
# Add a debugger!
[debugger]
support = true
# How to start the debugger.
[debugger.interactive]
transport = "localhost:0"
startCommand = ["dap-python", "main.py"]
# How to communicate with the debugger.
[debugger.interactive.integratedAdapter]
dapTcpAddress = "localhost:0"
# How to tell the debugger to start a debugging session.
[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"
[debugger.interactive.initializeMessage.arguments]
adapterID = "debugpy"
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true
# How to tell the debugger to start the debuggee application.
[debugger.interactive.launchMessage]
command = "attach"
type = "request"
[debugger.interactive.launchMessage.arguments]
logging = {}
# Configures the packager.
[packager]
language = "python3"
ignoredPackages = ["unit_tests"]
[packager.features]
enabledForHosting = false
# Enable searching packages from the sidebar.
packageSearch = true
# Enable guessing what packages are needed from the code.
guessImports = false
# These are the files that need to be preserved when this
# language template is used as the base language template
# for Python repos imported from GitHub
[gitHubImport]
requiredFiles = [".replit", "replit.nix", ".config", "venv"]
[languages]
[languages.python3]
pattern = "**/*.py"
[languages.python3.languageServer]
start = "pylsp"
go to shell and run: pip install pandas
Change the demographic_data_analyzer.py
to:
import pandas as pd
def calculate_demographic_data(print_data=True):
# Read data from file
df = pd.read_csv("adult.data.csv")
# How many of each race are represented in this dataset? This should be a Pandas series with race names as the index labels.
race_count = df['race'].value_counts()
# What is the average age of men?
average_age_men = df[df["sex"] == [Male]]["age"].mean().round(1)
# What is the percentage of people who have a Bachelor's degree?
num_bachelors = len[df['education'] == ['Bachelors']]
total_education = len[df["education"]]
percentage_bachelors = round(num_bachelors/total_education * 100, 1)
# What percentage of people with advanced education (`Bachelors`, `Masters`, or `Doctorate`) make more than 50K?
# What percentage of people without advanced education make more than 50K?
# with and without `Bachelors`, `Masters`, or `Doctorate`
higher_education = df[df['education'].isin[['Bachelor', 'Masters', 'Doctorate']]]
lower_education = df[~df['education'].isin[['Bachelor', 'Masters', 'Doctorate']]]
# percentage with salary >50K
non_percentage_higher = len(higher_education[higher_education.salary == ">50K"])
higher_education_rich = round(non_percentage_higher / len(higher_education) * 100, 1)
non_percentage_lower = len(lower_education[lower_education.salary == ">50K"])
lower_education_rich = round(non_percentage_lower / len(lower_education) * 100, 1)
# What is the minimum number of hours a person works per week (hours-per-week feature)?
min_work_hours = None
# What percentage of the people who work the minimum number of hours per week have a salary of >50K?
num_min_workers = None
rich_percentage = None
# What country has the highest percentage of people that earn >50K?
highest_earning_country = None
highest_earning_country_percentage = None
# Identify the most popular occupation for those who earn >50K in India.
top_IN_occupation = None
# DO NOT MODIFY BELOW THIS LINE
if print_data:
print("Number of each race:\n", race_count)
print("Average age of men:", average_age_men)
print(f"Percentage with Bachelors degrees: {percentage_bachelors}%")
print(f"Percentage with higher education that earn >50K: {higher_education_rich}%")
print(f"Percentage without higher education that earn >50K: {lower_education_rich}%")
print(f"Min work time: {min_work_hours} hours/week")
print(f"Percentage of rich among those who work fewest hours: {rich_percentage}%")
print("Country with highest percentage of rich:", highest_earning_country)
print(f"Highest percentage of rich people in country: {highest_earning_country_percentage}%")
print("Top occupations in India:", top_IN_occupation)
return {
'race_count': race_count,
'average_age_men': average_age_men,
'percentage_bachelors': percentage_bachelors,
'higher_education_rich': higher_education_rich,
'lower_education_rich': lower_education_rich,
'min_work_hours': min_work_hours,
'rich_percentage': rich_percentage,
'highest_earning_country': highest_earning_country,
'highest_earning_country_percentage':
highest_earning_country_percentage,
'top_IN_occupation': top_IN_occupation
}
https://replit.com/@SerLette/boilerplate-demographic-data-analyzer#demographic_data_analyzer.py
Running a code on my replit console is near impossible. It is so slow that it doesn’t complete installing of modules, talk more of running the actual python code. It was earlier suggested to turn guessImports = false
, but it rather doesn’t import the pandas module I need to run my program.
Above is my project and I can’t test run it for errors while writing the codes. What should I do?
Fork the repl and try fixing the errors there.
I think it’s not a Replit problem, there are some errors if I’m not mistaken.