python question I want to make display a bar graph of grade counts with these code results, what should I do? def Insert
Posted: Sat May 14, 2022 7:49 pm
python question
I want to make display a bar graph of grade counts with these
code results, what should I do?
def Insert(student):
name = input('Your Name : ')
#If no name found,
if (name not in student) == True:
#enter grade
cs = int(input('Please enter your cs grade : '))
eng = int(input('Please enter your eng grade : '))
math = int(input('Please enter your math grade : '))
print('Your grade has been entered.')
score = cs+eng+math
avg = round(score/3, 3)
#If the name is duplicate
else:
print('A student with the same name exists..')
return Insert(student)
student[name] = [cs, eng, math, score, avg]
person = student[name]
return student
# ----- grade output -----
def View(student):
print("=======================================================")
print('Grade : [cs, eng, math, score, avg]')
for key, value in student.items():
print(key,':', value)
print("=======================================================")
return student
# ----- search students -----
def Search(student):
search_name = input('Please enter the name of the student you want
to search : ')
# The search name matches the Key value in the dictionary
if(search_name in student) == True:
print("=======================================================")
print('Grade : [cs, eng, math, score, avg]')
print(search_name,':' , student.get(search_name),' ') #Gets the
value of the key from the dictionary => dic.get(key)
print("=======================================================")
else:
print('The name does not exist.')
print('If you want to search again, press 1. If you want to return
to the main screen, press 2..')
num = int(input('Enter a number : '))
if num ==1:
Search(student)
else:
main()
return student
# ----- grade correction -----
def Update(student):
update_name = input('Please enter the name of the student you want
to modify : ')
# The search name matches the Key value in the dictionary
if(update_name in student) == True:
print('cs, eng, math :')
#Enter Computer Science, English, and Math (overwritten)
cs, eng, math = map(int, input().split())
score = cs+eng+math
avg = round(score/3, 3)
#Key = Value
student[update_name] = [cs, eng, math, score, avg]
person = student[update_name]
else:
print('The name does not exist.')
print('Press 1 to re-enter the name of the student you want to
modify. Press 2 to return to the main screen.')
num = int(input('Enter a number : '))
if num ==1:
Update(student)
else:
main()
return student
# ----- Delete -----
def Delete(student):
delete_name = input('Please enter the name of the student you want
to delete : ')
# pop
if(delete_name in student) == True:
student.pop(delete_name)
return student
def main():
#student dictionary
student = dict()
print()
print("┌--------------------------------------------------------------------------------┐");
print("│ │");
print("│ A Grade Management Program │");
print("│ Created By Junseok Oh on 2022-04-24 │");
print("└--------------------------------------------------------------------------------┘\n");
print()
while True:
select = int(input("1.Insert 2.View 3.Search 4.Update 5.Delete
6.Exit \n"))
# ----- input grade -----
if select == 1:
student = Insert(student)
# ----- output -----
elif select ==2:
student = View(student)
# ----- search students -----
elif select == 3:
student = Search(student)
# ----- modify -----
elif select == 4:
student = Update(student)
# ----- delete -----
elif select == 5:
student = Delete(student)
else:
print("Exit.")
break
main()
I want to make display a bar graph of grade counts with these
code results, what should I do?
def Insert(student):
name = input('Your Name : ')
#If no name found,
if (name not in student) == True:
#enter grade
cs = int(input('Please enter your cs grade : '))
eng = int(input('Please enter your eng grade : '))
math = int(input('Please enter your math grade : '))
print('Your grade has been entered.')
score = cs+eng+math
avg = round(score/3, 3)
#If the name is duplicate
else:
print('A student with the same name exists..')
return Insert(student)
student[name] = [cs, eng, math, score, avg]
person = student[name]
return student
# ----- grade output -----
def View(student):
print("=======================================================")
print('Grade : [cs, eng, math, score, avg]')
for key, value in student.items():
print(key,':', value)
print("=======================================================")
return student
# ----- search students -----
def Search(student):
search_name = input('Please enter the name of the student you want
to search : ')
# The search name matches the Key value in the dictionary
if(search_name in student) == True:
print("=======================================================")
print('Grade : [cs, eng, math, score, avg]')
print(search_name,':' , student.get(search_name),' ') #Gets the
value of the key from the dictionary => dic.get(key)
print("=======================================================")
else:
print('The name does not exist.')
print('If you want to search again, press 1. If you want to return
to the main screen, press 2..')
num = int(input('Enter a number : '))
if num ==1:
Search(student)
else:
main()
return student
# ----- grade correction -----
def Update(student):
update_name = input('Please enter the name of the student you want
to modify : ')
# The search name matches the Key value in the dictionary
if(update_name in student) == True:
print('cs, eng, math :')
#Enter Computer Science, English, and Math (overwritten)
cs, eng, math = map(int, input().split())
score = cs+eng+math
avg = round(score/3, 3)
#Key = Value
student[update_name] = [cs, eng, math, score, avg]
person = student[update_name]
else:
print('The name does not exist.')
print('Press 1 to re-enter the name of the student you want to
modify. Press 2 to return to the main screen.')
num = int(input('Enter a number : '))
if num ==1:
Update(student)
else:
main()
return student
# ----- Delete -----
def Delete(student):
delete_name = input('Please enter the name of the student you want
to delete : ')
# pop
if(delete_name in student) == True:
student.pop(delete_name)
return student
def main():
#student dictionary
student = dict()
print()
print("┌--------------------------------------------------------------------------------┐");
print("│ │");
print("│ A Grade Management Program │");
print("│ Created By Junseok Oh on 2022-04-24 │");
print("└--------------------------------------------------------------------------------┘\n");
print()
while True:
select = int(input("1.Insert 2.View 3.Search 4.Update 5.Delete
6.Exit \n"))
# ----- input grade -----
if select == 1:
student = Insert(student)
# ----- output -----
elif select ==2:
student = View(student)
# ----- search students -----
elif select == 3:
student = Search(student)
# ----- modify -----
elif select == 4:
student = Update(student)
# ----- delete -----
elif select == 5:
student = Delete(student)
else:
print("Exit.")
break
main()