Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def AppendList():
- # This function creates an empty list and allows the user to add an infinite amount of numbers.
- numberList = []
- # Above I create an empty list and store it as a variable called 'numberList'
- while True:
- newNumbers = input("Please enter a number to add to the list. To begin sorting your list, type 'sort'.\n ")
- # The above while loop allows the user to endlessly enter numbers until they break the loop by typing 'sort'.
- if newNumbers == "sort":
- BubbleSort()
- break
- while True:
- try:
- numberList.append(int(newNumbers))
- # Above I append the users inputted numbers to the list.
- print("This is how the list currently looks: " + str(numberList) + ",")
- return numberList
- except ValueError:
- print("The value you have entered cannot be added to the list. Please ensure you only enter whole numbers.\n")
- AppendList()
- return numberList
- [Program Response]
- Welcome. What would you like the program to do?
- 1.Enter your name and append it to a text file
- 2.Enter a list of numbers and sort them
- 3.Exit the program
- 2
- Please enter a number to add to the list. To begin sorting your list, type 'sort'.
- Alice
- The value you have entered cannot be added to the list. Please ensure you only enter whole numbers.
- Please enter a number to add to the list. To begin sorting your list, type 'sort'.
- 123
- This is how the list currently looks: [123],
- No more swaps required.
- []
- List of numbers appended to the text file 'NumberLists.txt'
- Would you like to read the text file?
- 1.Yes
- 2.No
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement