Write a Program That Reads a Joke

Jokes Generator with python

In this Weblog article, we will learn how to Create Jokes Generator with Python. We will see the implementation in python.

Repository for Ultimate Resource in python. Drop a star if you observe it useful! Got anything to add? Open a PR on the same!

You lot can refer to my YouTube video tutorial for better Understanding

          1. Pyjokes Introduction
two. Generating jokes with Pyjokes

Pyjokes is a python library for one line jokes for programmers (jokes as a service). You can get funny 1-liner, mostly related to programming. This is a fun python library. It returns a random joke from the given category in the given language.

  • English — 'en'
  • Spanish — 'es'
  • Italian — 'it'
  • High german — 'de'
  • Galician — 'gl'
  • Basque — 'eu'
  • For geeky jokes -'neutral' (It is chosen by default)
  • For Chris Norris Jokes — 'chuck'.
  • If yous want all type of jokes — 'all'
  • There is 1 more than category known equally 'twister' which only works for the German Linguistic communication ('de') and by and large includes tongue twister.

If you lot wish to know more near it, you can refer to Pyjokes Documentation. Utilise this link to navigate to the documentation.

Now that y'all are aware of Pyjokes nuts, we can move frontwards to the coding department.

You tin can detect all the lawmaking at my GitHub Repository. Drib a star if you find it useful.

In order to access the Python library, you need to install it into your Python environment, use the following command to install pyjokes

          pip install pyjokes        

Now, permit's import the package in our python script.

          import pyjokes        

There are two methods in pyjokes-

  • get_joke()
  • get_jokes()

1. get_joke()

It just returns one joke at a fourth dimension. It is generated randomly.

Parameters — It has ii parameters- language and category.

Return Type — It returns string type (str).

Now, let'south retrieve the joke

          joke1 = pyjokes.get_joke(linguistic communication='en', category= 'all')                    #display the joke
impress(joke1)
#output:
#A programmer was found dead in the shower. Next to their trunk was a bottle of shampoo with the instructions 'Soap, Rinse and Echo'.

Permit'southward endeavour a different category:

          joke2 = pyjokes.get_joke(linguistic communication='en', category= 'neutral')          #display the joke
print(joke2)
#output:
#There are 10 types of people: those who sympathize trinary, those who don't, and those who accept never heard of information technology.

2. get_jokes()

It returns a list of jokes.

Parameter– The parameters are the same every bit above- language and category.

Render blazon– *It returns a list.

Now let's fetch some jokes.

          jokes = pyjokes.get_jokes(language='en', category= 'neutral')          for i in range(5):
print(i+1,".",jokes[i])

And you will get a list of jokes. You tin can alter the number the times the loop runs to fetch more number of jokes.

This is how yous generate jokes. This is all about the generating jokes with Python. That's information technology! simple, isn't it? Promise this tutorial has helped.

Yous tin play effectually with the library and explore more features and even brand utilize of Python GUI using Tkinter.

You can find all the code at my GitHub Repository. Driblet a star if you observe information technology useful.

Thank you for reading, I would honey to connect with you at Twitter | LinkedIn. I would recommend you to Check out the YouTube video of the aforementioned and don't forget to subscribe my Channel.

Exercise share your valuable feedback and suggestions!

You should definitely check out my other Blogs:

  • Python iii.9: All You need to know
  • The Ultimate Python Resource hub
  • GitHub CLI 1.0: All you need to know
  • Become a Amend Programmer
  • How to make your ain Google Chrome Extension
  • Create your ain Audiobook from whatever pdf with Python
  • You lot are Important & and then is your Mental Health!
  • pyjok.es
  • github.com/pyjokes/pyjokes
  • pypi.org/project/pyjokes

Encounter you in my side by side Web log article, Take care

strasserpoine1948.blogspot.com

Source: https://ayushi7rawat.medium.com/in-this-blog-article-we-will-learn-how-to-create-jokes-generator-with-python-d7d4b154dcdd

0 Response to "Write a Program That Reads a Joke"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel