#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. from random import choice def get_words(msg): msg += "? " while True: i = input(msg) if i: return i.lower() else: print("Type a", msg.rstrip("? ").lower()) continue def sent(noun, verb, adj): sent = [] sent.append("{0} {1} to the {2} show.".format(noun.capitalize(), verb, adj)) sent.append("The {2} {0} did a spin and {1} to the park.".format(noun, verb, adj)) sent.append("{0} made a {2} {1}.".format(noun.capitalize(), verb, adj)) sent.append("The people and {0} are {1} for the {2} man.".format(noun, verb, adj)) print(choice(sent)) def main(): print("adlibs.py: prints random short sentances depending on user input.", "Use ^C or ^D to exit.", sep="\n") while True: try: noun = get_words("Noun") verb = get_words("Verb") adj = get_words("Adjective") sent(noun, verb, adj) except (KeyboardInterrupt, EOFError): print("\n") break if __name__ == "__main__": main()