How to use replit data base to store data from another replit!

I have a replit that quizzes students and put grades in the text file “student.txt” with their name eg.
“cliff.txt” I want to find all the students’ answers so I can grade the class. I want to put answers in replit database because the answers do not persist if you run from another different student. (other students phones or PC) I would like to store answers in database. I need another replit to print list of all students in the database. I will create that code but how to address the database in student’s test and recall it in my database query code? The replit documentation is really poor on this! give an example if possible. I am using python.

from replit import db

# Function to check if the given answer is correct
def check_answer(question, answer):
    correct_answers = {
        1: "a",
        2: "b",
        3: "b",
        4: "b",
        5: "d",
        6: "c",
        7: "c",
        8: "a",  # Corrected answer
        9: "a",
        10: "b"
    }

    # Retrieve the correct answer for the given question
    correct_answer = correct_answers.get(question)

    # Compare the answer provided by the student with the correct answer
    if answer.lower() == correct_answer:
        return True
    else:
        return False

# Function to calculate the percentage of correct answers
def calculate_percentage_correct(answers):
    num_questions = len(answers)
    num_correct = sum(answers)
    percentage = (num_correct / num_questions) * 100
    return percentage

# Function to calculate the grade based on the percentage of correct answers
def calculate_grade(percentage):
    if percentage >= 70:
        return "Pass"
    else:
        return "Fail"

# Main program
def main():
    # Get student's name and date
    student_name = input("Enter student's name: ")
    exam_date = input("Enter exam date (e.g., June 6, 2023): ")

    # List to store student's answers
    student_answers = []

    # Iterate over the questions
    for i in range(1, 11):
        print(f"\nQuestion {i}:")
        print(questions[i])
        answer = input("Your answer: ")

        # Check if the answer is correct
        if check_answer(i, answer):
            print("Correct answer!")
            student_answers.append(1)
        else:
            print("Incorrect answer!")
            student_answers.append(0)

    # Calculate the percentage of correct answers
    percentage_correct = calculate_percentage_correct(student_answers)

    # Calculate the grade based on the percentage of correct answers
    grade = calculate_grade(percentage_correct)

    # Print the percentage of correct answers and the grade
    print("\nPercentage Correct: {:.2f}%".format(percentage_correct))
    print("Grade: {}".format(grade))

    # Create a file name using the student's name
    file_name = "{}_results.txt".format(student_name.replace(" ", "_"))

    # Write student's information, answers, percentage correct, and grade to a text file
    with open(file_name, "w") as file:
        file.write("Student Name: {}\n".format(student_name))
        file.write("Exam Date: {}\n".format(exam_date))
        for i, answer in enumerate(student_answers, start=1):
            file.write("Question {}: {}\n".format(i, answer))
        file.write("Percentage Correct: {:.2f}%\n".format(percentage_correct))
        file.write("Grade: {}\n".format(grade))
        #db[student_name] = 70.0
        #db.db_url['https://replit.com/@panagranit/quiz-phlebotomy#main.py'] 

if __name__ == "__main__":
    # Dictionary to store the questions
    questions = {
        1: "Which tube is commonly used for coagulation tests?\n\
        a) Blue top tube\n\
        b) Red top tube\n\
        c) Lavender top tube\n\
        d) Grey top tube\n",
        2: "What type of test is typically performed using a lavender top tube?\n\
        a) Blood glucose test\n\
        b) Complete blood count (CBC)\n\
        c) Liver function test\n\
        d) HIV test\n",
        3: "Which tube is used for serum chemistry tests?\n\
        a) Blue top tube\n\
        b) SST tube\n\
        c) Red top tube\n\
        d) Lavender top tube\n",
        4: "What does the abbreviation PT/PTT stand for?\n\
                b) Prothrombin Time/Partial Thromboplastin Time\n\
        c) Plate Count/Total Protein Test\n\
        d) Potassium Test/Toxicology Test\n",
        5: "Which tube is commonly used for blood alcohol level testing?\n\
        a) Blue top tube\n\
        b) SST tube\n\
        c) Red top tube\n\
        d) Grey top tube\n",
        6: "Which test is performed to assess long-term blood sugar control?\n\
        a) Prothrombin Time/Partial Thromboplastin Time\n\
        b) Complete Blood Count\n\
        c) Hemoglobin A1c\n\
        d) Glucose Tolerance Test\n",
        7: "Which tube is used for serology tests?\n\
        a) Blue top tube\n\
        b) SST tube\n\
        c) Red top tube\n\
        d) Lavender top tube\n",
        8: "Which additive is present in a grey top tube?\n\
        a) Sodium Fluoride\n\
        b) Clot activator gel\n\
        c) No additive\n\
        d) Sodium Citrate\n",
        9: "What does the abbreviation INR stand for?\n\
        a) International Normalized Ratio\n\
        b) Immunoglobulin Ratio\n\
        c) Insulin Neutrophil Ratio\n\
        d) Inflammatory Marker Ratio\n",
        10: "What type of test is typically performed using an SST tube?\n\
        a) Coagulation test\n\
        b) Serum chemistry test\n\
        c) Serology test\n\
        d) Blood glucose test\n"
    }

    main()




de here
  • This is REplit documentation reference to question I am asking but I do not understand the code and general concept?

A simple proxy to Repl.it Database.

Great for sharing one database among many repls.

Warning: you might want to add authentication to this, otherwise
anyone can access the database!


import os
import flask
import requests

app = flask.Flask(__name__)
sess = requests.Session()

@app.route("/", defaults={"path": ""}, methods=["GET", "POST", "DELETE"])
@app.route("/<path:path>", methods=["GET", "POST", "DELETE"])
def proxy(path):
  url = os.environ["REPLIT_DB_URL"]
  if flask.request.path != "/":
    url += flask.request.path

  req = requests.Request(flask.request.method, url, data=flask.request.form, params=flask.request.args).prepare()
  resp = sess.send(req)

  proxy_resp = flask.make_response(resp.text)
  proxy_resp.status_code = resp.status_code
  for k, v in resp.headers.items():
    proxy_resp.headers[k] = v

  return proxy_resp
    
# uncomment this to run:
app.run("0.0.0.0")

I think this means that I have to have Flash installed to have this program send info If my replit url for the program quiz is https://replit.com/@panagranit/quiz-phlebotomy
where would I put that in the above code to access the database?

What does return proxy_resp do ?

I am confused why you need another repl to print these?

4 Likes

just imagine you’re a teacher you have 10 students. And you want to grade them online using whatever device they’re using. You give them your replit quiz ( url link)that you generated in python and they finish the quiz and it puts the students answers in a text file. That particular text file is not persistent in the Replit because the program starts over for the next student there’s no way I can access the previous students answers unless I use a persistent database to store each students answers . The students are taking the test asynchronously at different times not at the same time and not on the same PC and not in the same location.

That’s not too hard to understand!

1 Like

but … it is. You’re reinventing the wheel if you are truly using this for educational purposes, then use replit for edu (scroll to for edu) which does what you want except more robustly by a professional team (basically what you are doing except that you can just send your students some assignment and they have a repl that they complete it in which you can view and grade easily)

6 Likes

Hey thanks for your question! Are you currently using Teams for Education? As @bigminiboss said, it has features that allow you to create projects for your students to fork, then you can review and maintain access to each student’s work without having to overwrite the original project. It is free for teachers!

And please remember to be kind to others in the forum who are helping you, it’s ok to be confused and ask for more clarity.

5 Likes

OK, this a free service and will I learn what I am asking … code… etc…?
I see teams let up to 10 people collaborate on a project which means that if they run the one replit the answers will be persistent. because they are all signed in to team I guess Ok.?. but I could alternatively create a class replit and give them an ID and password that I create for the class and let them sign in and get lasting data, OK

I can see how that is more secure possibly initially than geting a Db and letting them access … that is something that I want to know as well … how to set up password for my database…

But I want to learn how to access the database in seperate replits still.

1 Like

Teams for Edu is free for teachers!

3 Likes

but my original question was can you help me regarding this database which solution that was given as a solution for another problem I want to learn how to use the database and how to address it from another Replit? if no one knows how to do it I understand. But there must be one person in the company that knows how to do it?

we know how to use replit database. What we’re saying is that basically your problem that you’re trying to solve with replit db is already solved and you shouldn’t reinvent the wheel. Thus, we can help you learn replit db but we’re saying that there’s no point in doing this specific task

3 Likes

That is not nice… you want limit my knowledge by saying use this other tech. I do not like to be limited by someone like this. You are limiting my use of the data base here which is clearly something that the powers that be have sanctioned. I do not have to justify a project to you. you are not my arbiter. what gives you that right? So I must justify my project to you? No, that is not right. You have given an alternative solution but that is not the solution that I asked for which will help me become a better programmer.

He is not limiting your knowledge, he is simply informing you that there is already a tool that addresses the problem you want to fix.
This is not limiting; he is preventing you from doing redundant work, as there is a solution for your situation already available for use.
Saving time is not a way to limit knowledge; it is a way to increase efficiency.

4 Likes

in addition to this I already stated multiple times that we are happy to help, just we don’t think we want to go about doing this nor do we think it’s an efficient use of your time.

3 Likes

Nor will doing it in a more difficult way, though?

People have said many times here that we just want to help you, though…

Never said you were.

How? We’re literally trying to save you time by telling you that there’s an easier method to do what you want to do.

The only staff in this conversation was Lena. The rest of us are volunteering our time and I think you ought to have a little more respect for us doing that.

No? As bigminiboss said earlier, we can help you we can do what you want, we’re just choosing not to because it’s wasting your and our time :woman_shrugging:


No offence or anything (seriously, I don’t mean to be offensive by this next question), but did you put any thought into what you said just now before posting it?

7 Likes

This is intimidation a normal defense mechanism. by persons who have fragile egos. It works on immature people i am sure but not today. thank you for your limited help!

1 Like

ok my guy let me get one thing straight, please read the very very big text:

we can help you. We will help you. We are volunteers and we feel like it’s a waste of our time to do this and that it would be much easier for you to use something else

you know what here:
here’s how you make something called a server. This server functions as essentially a “computer” that anyone can access specific elements of. For example, if you want to let many people see & edit from different computers then you can user a “server.”
Repl_1_server (make sure cliff.txt exists):

from flask import Flask

app = Flask(__name__)

@app.route('/stuff')
def get_stuff():
     return open("cliff.txt").read()

@app.route('/stuff', method=["POST"])
def post_stuff():
    with open("cliff.txt", "w") as f:
        f.write(request.json["text"])
    return "done"

app.run("0.0.0.0")

Repl_2_client:

from requests import get

print(get("Repl_1_server.panagranit.repl.co/stuff").text)

this is unsecured and you can add some more security later but this is a simple ver

5 Likes

@panagranit could you please be kind to the people here in the community » Replit Ask Community Standards. They are trying as hard as they can to help you, although they aren’t getting payed: like @QwertyQwerty88 said, they are volunteers that genuinely want to help out. If you can’t say something nice don’t say it at all, you are tearing them down, even gaslighting them. Please, just be kind. You can do it your way, you don’t have to be rude about it, they are just trying to help you. Replit Ask is a place to help, you asked a question, they answered out of trying to help, if you don’t want their help don’t go to Replit Ask for your answers. Have a nice day :grinning:!

5 Likes