I'm trying to automate some of the grading process for a beginners Python class. The students provide a Python program that prompts the user for 5 items and the monthly amount for those 5 items. The students then display a budget displaying the items, the monthly amount, and the yearly amount. I would like to write a python script that will execute all 65 students programs and have the program provide the input for those 5 items and the monthly amount. I would like the input variables to be random from a list and random float amount. Does this seem feasible to do from the program or do the variables and monthly amounts need to be provided from the command line? The overall goal is to provide automatic input values for the 5 items and the amount and then the student's print statements will be printed to the console, making it quicker to provide a grade based on the student's output.
Right now, my code prompts the teacher for the path to the directory where the student's assignments are held and stores each file path in a list. Now, I'm trying to figure out how to execute each Python file from the list and when each student's program prompts for the user input, my script will provide the input automatically. The prompt strings are specific which allows me to specify an item vs an amount. EG. "Please enter item 1:" (input item name), "Please enter item amount: " (input float amount)
This is my Pseudo Code:
import os
list_files = ["student1.py", "student2.py" ,....]
list_items = ["mortgage", "groceries", "insurance"]
list_amounts = [123.34, 1024.11, 32.3]
Now I need to figure out how to execute each file and have the program provide the input from list_items
and list_amounts
. I'm looking for advice on the best way to approach this. I would prefer to have the program provide the input from these lists and not have the teacher type in the values as you would through the arguments.
For example,
python student1.py mortgage 123.34 groceries 32.3 insurance 1024.11
.
How can I do this? Preferably not through the argv [ ]