Advertisement
MrsMcLead

ECS lists

Nov 22nd, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter.simpledialog
  3. import tkinter.messagebox
  4.  
  5. root = Tk()
  6. w = Label(root, text="Lists")
  7. w.pack()
  8.  
  9. names = ["", "", "", ""]
  10.  
  11. tkinter.messagebox.showinfo("Get Ready", "I'm going to ask you for 4 names")
  12.        
  13. names[0] = tkinter.simpledialog.askstring("Name 1", "Please enter first name")
  14. names[1] = tkinter.simpledialog.askstring("Name 2", "Please enter second name")
  15. names[2] = tkinter.simpledialog.askstring("Name 3", "Please enter third name")
  16. names[3] = tkinter.simpledialog.askstring("Name 4", "Please enter fourth name")
  17.        
  18.        
  19. tkinter.messagebox.showinfo("Reversed", "Here are the names in the reverse order:\n" +
  20.                                   names[3] + "\n" +
  21.                   names[2] + "\n" +
  22.                                   names[1] + "\n" +
  23.                   names[0] + "\n")
  24.  
  25. #   This file deals with List.  You can think of them as a cupboard with different
  26. #   numbered shelves to store things.  Run the file.  Answer the
  27. #   questions below.
  28. #   1.  On the line:
  29. #            names = ["", "", "", ""]
  30. #
  31. #       What symbols surround all the quotes?
  32. #
  33. #   2.  On the line:
  34. #            names = ["", "", "", ""]
  35. #
  36. #   How many sets of quotes are there?
  37. #
  38. #   3.  On the line:
  39. #               names[0] = tkSimpleDialog.askstring("Name 1", "Please enter first name")
  40. #
  41. #       Why do you think the 0 is for?
  42. #
  43. #   4.  Why do you think the names are output in the reverse order that you entered them?
  44. #   5.  Make the code ask for a fifth name.  Write down the changes you made.
  45. #   6.  Have the code output the fifth name with the others.  Write down what you did.
  46. #   7.  Get the code to print the names in the original order that they were entered.
  47. #       Write down the changes you made.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement