Can it be cleaner? or improved?
sweetphilly2 (0)

Repl: https://repl.it/join/ivqffjsn-sweetphilly2

Hello,

Two things I'm looking for help with:

  • I'm looking for a better way to take in a line of text (in my code's case, some song information). I want the user to be able to type in one line of information; currently, the user has to type in two lines of information (i.e. track number then song title). For example, the user should be able to type in "1 Dream On" or "1. Dream On"
  • A better way to break the loop without using a keyword or phrase. Since the title of a song could be practically any name, I can't use that input as a way to break the loop. For instance, with the loop break depending on the user inputting "done", this disallows song title's from being set to "done".
You are viewing a single comment. View All
Answered by malvoliothegood (364) [earned 5 cycles]
View Answer
malvoliothegood (364)

@sweetphilly2
Yes, I guess that could enter "One" for the track number as well. Validating user input is a mission. I guess you could test to see if the entered track value could be converted to an int. If an error is thrown then this could be conveyed to the user and they could enter the value again or you could restart the program.