Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. def menu():
  2. while True:
  3. print('Please choose one of the following options: ')
  4. print('1. Read a file numbers')
  5. print('2. Sort the numbers from file')
  6. print('3. Quit the program\n')
  7.  
  8. command = int(input("Enter a command: "))
  9.  
  10. if command == 1:
  11. print("Reading the file numbers.txt")
  12. valid = False
  13. try:
  14. f = open('numbers', 'r')
  15. valid = True
  16. except IOError:
  17. print("That file does not exist!")
  18. if valid:
  19. numbers(f)
  20. f.close()
  21.  
  22. elif command== 2:
  23. heap_sort(heap[1:])
  24.  
  25. elif command == 3:
  26. print('Program is now terminating')
  27. break
  28.  
  29. else:
  30. print("Invalid input number.\n")
  31.  
  32. def numbers(nums):
  33. test=[]
  34. for _ in nums:
  35. test += _.split()
  36. for i in test:
  37. heap_insert(heap,int(i))
  38. print("All numbers have been inserted")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement