Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import pickle#This is me importing my Pickle.def enter_list():
  2. def enter_list():
  3. mylist = []
  4. while True:
  5. #user_input = raw_input("Enter something:")
  6. #if user_input == "quit":
  7. #break
  8. input1=input("you entered:")
  9. if input1=="exit":
  10. #This if statement will exit the entering mode if the user types in e.
  11. break
  12. mylist.append(float(input1))
  13. print("your numbers are")
  14. print(mylist)
  15. return mylist
  16.  
  17.  
  18. def sortingasd(num_list):
  19.  
  20. swapped = True
  21. while swapped:
  22. swapped = False
  23. p = (0)
  24. for i in range(len(num_list)-1):# This working until the length.
  25. q = p+(1)
  26. if num_list[p] > num_list[q]:
  27. num=num_list[p]
  28. num_list[p]=num_list[q]
  29. num_list[q]=num
  30. num_list[q]=num
  31. swapped = True
  32. p=p+(1)
  33. return num_list
  34.  
  35. def sortingdsc(num_list):
  36. swapped = True
  37. while swapped:
  38. swapped = False
  39. p = (0)
  40. for i in range(len(num_list)-1):# This is printing the lenth of number list.
  41. q = p+(1)
  42. if num_list[p] < num_list[q]:#this code is telling the program if P is greater than q then process the code below.
  43. num=num_list[p]#This code is telling the program num is = to num_list.
  44. num_list[p]=num_list[q]
  45. num_list[q]=num
  46. num_list[q]=num
  47. swapped = True
  48. p=p+(1)
  49.  
  50. return num_list
  51.  
  52.  
  53. num_list = []
  54. num_list = enter_list()
  55. #This input statement is asking the user if they want it in dsc or asd order.
  56.  
  57. enterasdordsc= input("please enter either asd or dsc:")
  58.  
  59.  
  60. with open('linearprogrammingfile.pkl', 'wb') as picklefile:#This code open's the Pickle file.
  61. pickle.dump(num_list, picklefile)#This code is dump my code into linearprogrammingfile.pkl
  62. picklefile.close()#This is closing the Pickle file.
  63. with open ('linearprogrammingfile.pkl', 'rb') as picklefile:
  64. num_list = pickle.load(picklefile)
  65. picklefile.close()
  66. if enterasdordsc== "asd":
  67. print (sortingasd(num_list))
  68. with open('linearprogrammingfile.pkl', 'wb') as picklefile:
  69. pickle.dump(num_list, picklefile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement