- # Cut and paste this text into a text editor and save in a file
- # christmasgreetings.py
- # then execute it as a Python program
- # AUTHOR Paul Curzon, QMUL www.cs4fn.org
- # This is a christmas card writing program to save all that time writing cards
- # This program was inspired by the 'first creative program' written by Chris Strachey,
- # It was a love letter writing program
- # The program provides a few template sentences to use.
- # It uses them in a random order, filling them with words from word lists
- # The word lists are for different grammatical categories like nouns and verbs
- # Modify this program by adding new words to the word list
- # And adding new sentence templates
- # Alternatively modify it to be a christmas card love letter
- # Or modify it for some other occasion
- import random
- # Define global constants
- # This gives the number of sentences the program can choose from
- # Add 1 to this number for each new sentence template you add to the program
- NUMBER_OF_TEMPLATES = 3
- # Pick a word at random from a given word list removing it so it isn't used again
- def ChooseWord(wordlist) :
- word = random.choice(wordlist)
- wordlist.remove(word)
- return word
- # Pick a random number from a list of integers removing it so it isn't used again
- def PickRandomNumber(ns) :
- n = random.choice(ns)
- ns.remove(n)
- return n
- # Sentence Template
- # I wish you a ADJECTIVE NOUN.
- def IWishYou(adjectives, nouns) :
- noun = ChooseWord(nouns)
- adjective = ChooseWord(adjectives)
- print("We wish you a " + adjective + " " + noun + ".")
- # Sentence Template
- # I hope VERB you ADVERB.
- def IHopeTo(verbs, adverbs) :
- verb = ChooseWord(verbs)
- adverb = ChooseWord(adverbs)
- print("We hope " + verb + " you " + adverb + ".")
- # Sentence Template
- # Have a ADJECTIVE NOUN.
- def HaveA(adjectives, nouns) :
- adjective = ChooseWord(adjectives)
- noun = ChooseWord(nouns)
- print("Have a " + adjective + " " + noun + ".")
- # Sentence Template
- # SALUTATION!
- def Salutation(salutations) :
- salutation = ChooseWord(salutations)
- print()
- print(salutation + "!")
- # Sentence Template
- # END Q
- def SignOff(endings) :
- end = ChooseWord(endings);
- print(end);
- print("TSSFL Open Discussion Forums");
- # Create a christmas greeting using the template sentences and word lists below
- # Always start with a salutation and end with a sign off
- # In between choose the templates in a random order and substitute in words from
- # the appropriate word lists at random
- def GenerateChristmasGreeting() :
- salutations = ["Happy Christmas", "Merry Christmas", "Season's Greetings", "Happy New Year"]
- adjectives = ["wonderful", "joyous", "peaceful", "relaxing", "great"]
- nouns = ["holiday", "time", "few weeks", "Christmas"]
- verbs = ["to see", "to catch up with", "to be with", "to meet up with"]
- adverbs = ["soon", "in the new year", "sometime soon", "before long"]
- endings = ["With love", "Best wishes", "Wish you a blessed 2021"]
- Salutation(salutations)
- templatesleft = list(range(0,NUMBER_OF_TEMPLATES))
- while len(templatesleft)>0 :
- sentencechoice = PickRandomNumber(templatesleft)
- if (sentencechoice == 0) :
- IWishYou(adjectives, nouns)
- elif (sentencechoice == 1) :
- IHopeTo(verbs, adverbs)
- elif (sentencechoice == 2) :
- HaveA(adjectives, nouns)
- else :
- print("We're lost for words")
- SignOff(endings)
- GenerateChristmasGreeting()
-
- Active Topics
-
-
- by Eli 10 hours ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 328 Views 37766
- by Eli 10 hours ago Re: What is in Your Mind? View the latest post Replies 705 Views 303499
- by Eli 4 days ago Russia Invades Ukraine View the latest post Replies 663 Views 238501
- by Eli 6 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 7934
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 325
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24934
- by Eli 2 weeks ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 70477
- by Eli 2 weeks ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 58501
- by Eli 2 weeks ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 18585
- by Eli 3 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 20902
-
Christmas and New Year Greetings in Python
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5387
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Copy and paste the code below into this box (the code is taken from here), run it to get your Christmas and New Year Greetings
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Similar Topics
- Replies
- Views
- Last post
-
- Information
-
Who is online
Users browsing this forum: No registered users and 1 guest