Advertisement
scorpion2018

ELEMENTARY DATABASE

Dec 3rd, 2018
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. Problem Description:
  2. In this program we are going to explore a very elementary ‘database’ using Python. Your program should create and store a list of 20 student names and their corresponding scores. Then prompt the user to enter a student name and then display the student’s name along with his/her corresponding score. The user should be able to keep looking up student scores until he/she enters the single character ‘q’ to quit the program.
  3. Inputs
  4. Your Python program should accept a name as input and keep asking for names until they enter ‘q’ to quit.
  5. Output
  6. Your program should print the corresponding student’s name and score. Please see examples of output below.
  7. Approach
  8. 1. Start by entering and running the following Python code
  9. names = ['Jim', 'Sarah', 'Jason', 'Lynne', 'Ginny', 'Joe', 'Susan'] print (names)
  10. You should see that Python displays your list of names.
  11. 2. Now see what happens when you change the second line to
  12. print (names[0] + ‘, ‘ + names[1])
  13. You should see that Python prints the first two names. It is worth noting that names[0] displays the first name in the list and names[1] displays the second name.
  14. 3. Now write a loop to display all the names in the list, one per line. Your program will look like this
  15. for i in range (0, 7):
  16. print (...)
  17. where you have to fill in the ...
  18. 4. Now add a second list to your program comprising integers, which will represent
  19. the scores the students got on a particular test:
  20. scores = [88, 92, 95, 84, 85, 92, 89]
  21. The idea is that n-th score in the score list corresponds to the n-th student in the
  22. names list.
  23. 5. Modify your program in Python to prompt the user to enter a student name and
  24. then display the student’s name along with his/her corresponding score.
  25. ========== RESTART: C:/Temp/list.py =============
  26. Please enter the name: Ginny Ginny scored 85
  27. >>>
  28. 6. Finally, extend your program so the user can keep looking up student scores until he/she enters the single character ‘q’ to quit the program.
  29. Examples of output
  30. Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
  31. Type "copyright", "credits" or "license()" for more information.
  32. >>>
  33. =================== RESTART: C:/Temp/a09.py =====================
  34. Please enter the name: Ginny Ginny scored 85
  35. Please enter the name: Susan Susan scored 89
  36. Please enter the name: Jim Jim scored 88
  37. Please enter the name: q#Create lists
  38. names = ["Jim", "Sarah", "Jason", "Lynne", "Ginny", "Joe", "Susan"]
  39. scores = [88, 92, 95, 84, 85, 92, 89]
  40.  
  41. *******************************************************************************************************************************************************************THIS IS MY CODE BELOW ***************************************************************************************************************************
  42.  
  43. #Asking user to enter name
  44. namegiven = input ('Please enter name:')
  45.  
  46. #Search through my names list to find the scores
  47. while namegiven != 'q':
  48. for x in range (6):
  49. if names [x] == namegiven:
  50. print (names [x], " ", scores [x])
  51. else:
  52. print ("Not found, please enter name from list")
  53. namegiven = input ('Please enter name: ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement