Answer To: Get input from the user towrite the following information to a file: Student name Assignment average...
Vaibhav answered on Oct 17 2021
JupyterNotebook.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Method searchStudentRecord() is used to search the grades of a student with the specified name. If the record with the specified name is present, it will return the details. Otherwise returns an empty string."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def searchStudentRecord(name):\n",
" data = \"\"\n",
" name = name.lower()\n",
" with open(\"studentData.txt\", \"r\") as file:\n",
" for line in file.readlines():\n",
" if(line.find(name) != -1):\n",
" data = line\n",
" break\n",
" file.close()\n",
" return data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Method addStudentRecord() is used to get input from the user to write the information to a file."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def addStudentRecord():\n",
" with open(\"studentData.txt\", \"a\") as file:\n",
" print(\"Enter the details mentioned below\")\n",
" print()\n",
" name = input(\"Enter student name: \")\n",
" name = name.lower()\n",
" print()\n",
" assignmentGrade = float(\n",
" input(\"Enter assignment average grade upto 2 decimal : \"))\n",
" print()\n",
" midtermGrade = float(\n",
" input(\"Enter midterm exam grade upto 2 decimal : \"))\n",
" print()\n",
" finalProjectGrade = float(input(\"Enter final project grade : \"))\n",
" print()\n",
" finalGrade = float(input(\"Enter final exam grade : \"))\n",
" file.write(' '.join(str(i) for i in [\n",
" name, assignmentGrade, midtermGrade, finalProjectGrade, finalGrade]))\n",
" file.write('\\r\\n')\n",
" print(\"Student details successfully added to the file.\")\n",
" file.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The starting point of the execution. Call this...