This is a follow up of my other thread on 10 Green Bottles. I now want to know how i can make my input only accept some words/numbers. If the wrong word/number is written, it prompts you to type again. If the word typed match's an accepted word, it passes and runs through the rest of the code. Code:
def main():
num1=int(input('Pick a number between 10 and 30: '))
hue=str(input('Pick a colour; Red, Green, Blue: '))
numbers =[ 'no', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen', 'Twenty', 'Twentyone', 'Twentytwo', 'Twentythree', 'Twentyfour', 'Twentyfive', 'Twentysix', 'Twentyseven', 'Twentyeight', 'Twentynine', 'Thirty' ]
text_one = hue +' bottle%s\nHanging on the wall'
text_two = "And if one " + hue + " bottle\nShould accidentally fall\nThere'll be"
text_three =' \n'
with open(numbers[num1] + ' ' + hue + ' Bottles.txt', 'w') as a:
for l in range(num1, 0, -1): #
a.write(numbers[l]+ ' ')
if l == 1:
a.write(text_one % '' +'\n')
else:
a.write(text_one % 's' +'\n')
a.write(numbers[l] + ' ')
if l == 1:
a.write(text_one % '' + '\n')
else:
a.write(text_one % 's' + '\n')
a.write(text_two + ' ')
a.write(numbers[l-1] + ' ')
if (l - 1) ==1 :
a.write(text_one % ''+'\n')
else:
a.write(text_one % 's'+'\n')
a.write('\n' + '\n')
if __name__ == '__main__':
main()