Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. def AppendList():
  2. # This function creates an empty list and allows the user to add an infinite amount of numbers.
  3. numberList = []
  4. # Above I create an empty list and store it as a variable called 'numberList'
  5. while True:
  6. newNumbers = input("Please enter a number to add to the list. To begin sorting your list, type 'sort'.\n ")
  7. # The above while loop allows the user to endlessly enter numbers until they break the loop by typing 'sort'.
  8. if newNumbers == "sort":
  9. BubbleSort()
  10. break
  11. while True:
  12. try:
  13. numberList.append(int(newNumbers))
  14. # Above I append the users inputted numbers to the list.
  15. print("This is how the list currently looks: " + str(numberList) + ",")
  16. return numberList
  17. except ValueError:
  18. print("The value you have entered cannot be added to the list. Please ensure you only enter whole numbers.\n")
  19. AppendList()
  20. return numberList
  21.  
  22. [Program Response]
  23. Welcome. What would you like the program to do?
  24. 1.Enter your name and append it to a text file
  25. 2.Enter a list of numbers and sort them
  26. 3.Exit the program
  27. 2
  28. Please enter a number to add to the list. To begin sorting your list, type 'sort'.
  29. Alice
  30. The value you have entered cannot be added to the list. Please ensure you only enter whole numbers.
  31.  
  32. Please enter a number to add to the list. To begin sorting your list, type 'sort'.
  33. 123
  34. This is how the list currently looks: [123],
  35. No more swaps required.
  36. []
  37. List of numbers appended to the text file 'NumberLists.txt'
  38. Would you like to read the text file?
  39. 1.Yes
  40. 2.No
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement