Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Spandan Sehgal
Spandan Sehgal

Posted on

     

X-Mas Wisher in python

Intro

Hello everyone sorry for the late post as you might now that I am a student so that's why I got loads of classwork to do that's why this post is late . So as you know that X-Mas / Christmas is coming close so in today's post I will be telling you how to make an X-Mas Wisher in Python.

Let's Get started !

Importing the required modules

main.py

#Making an X-Mas Wisher using python#importing the required modulesimportrandom
Enter fullscreen modeExit fullscreen mode

For printing the wishes we also need a file which contains wishes so first create a file named wishes.txt

Wishes.txt

Happy X-MasSanta Claus is coming with some exciting gifts!Wishing you a Christmas that's merry and bright!I hope your holiday season is full of peace, joy and happiness!Merry Christmas with lots of loveI hope your Christmas is filled with joy this year!May this season find you among those you love, sharing in the twin glories of generosity and gratitude.Christmas is not an external event at all, but a piece of one’s home that one carries in one’s heart.We clap hands and welcome the Peace of Christmas.We beckon this good season to wait a while with us.Christmas isn’t just a day. It’s a frame of mind.Wishing you a season that’s merry and bright with the light of God’s love.Christmas gives us an opportunity to pause and reflect on the important things around us.
Enter fullscreen modeExit fullscreen mode

Now we will open the file and choose a random line to print from it

#opening and reading the filelines=open('wishes.txt').read().splitlines()#using random to choose any random line from the fileWish=random.choice(lines)#printing the lineprint(Wish)
Enter fullscreen modeExit fullscreen mode

Now with this done we have successfully created a X-Mas Wisher in python.

I hope you enjoyed this post.
feel free to write down your suggestions/doubts in the comments section and comment "X-Mas Yaay!" if you see this

That's it for today, stay safe and do take very good care of yourselves.
Thanks

Top comments(3)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
morphzg profile image
MorphZG
Web developer and casual writer. Javascript, Node.js, React.js, Python, SQL, Linux... | From full stack web apps to cloud computing.
  • Location
    Croatia
  • Joined
• Edited on• Edited

Always happy to find some simple programs and than try to build upon it. Some people say its best to use "with" block when opening files because it takes care of both opening and closing it. Not sure why it is important, maybe it have something with memory usage.

Edit:geeksforgeeks.org/with-statement-i...

CollapseExpand
 
sehgalspandan profile image
Spandan Sehgal
Hey there! I'm a 16 yo curious student who's into coding since 4yrs and writing blogs. Always curious to learn more and discuss!

Thanks for the suggestion

Have a good day

CollapseExpand
 
sehgalspandan profile image
Spandan Sehgal
Hey there! I'm a 16 yo curious student who's into coding since 4yrs and writing blogs. Always curious to learn more and discuss!

How's the post comment about it !
if you have any suggestions / doubts then also you feel free to comment here.
Have a good day!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hey there! I'm a 16 yo curious student who's into coding since 4yrs and writing blogs. Always curious to learn more and discuss!
  • Location
    India
  • Education
    Gurugram
  • Pronouns
    he/him
  • Work
    Student
  • Joined

More fromSpandan Sehgal

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp