Skip to content
Advertisement

Develop a module to help generate lottery tickets in python

I have made the two modules (which are incomplete I guess) for the main function but couldn’t make the main function

Create a script file named lottohelper_using_getopt.py for the module in your current workspace/directory.

Define a function named lotto649 (in the script/module file) which can generate and return six different random integers in a list from range [1,49]. (1 point)

Define a function named lottomax (in the script/module file) which can generate and return seven different random integers in a list from range [1,50]. (1 point)

Import the lottohelper_using_getopt module in Jupyter notebook, and call the two functions lotto649 and lottomax, and report your result in a Jupyter notbook cell. (1 point)

You have to use the randrange() or randint() function from the random module https://docs.python.org/3/library/random.html.

Define the main function (in the script/module file) which will allow you to provide options, through the getopt module, (3 point) such as

help information to show how to use it, choosing type between 649 and MAX, using -v or –verbose to control verbosity. You need to use a positional argument to specify how many tickets you want it to generate.

In the main function, once you parsed the parameters, you need to write code to generate multiple tickets. (1 point)

Run the lottohelper_using_getopt.py in command line (or in a Jupyter lab cell using !python lottohelper_using_getopt.py ), e.g. python lottohelper_using_getopt.py -v 1 –type MAX 4 which means you tell your script to generate 4 LottoMax tickets (i.e. four sets of random numbers printed on the screen). Report your result in a notebook Raw cell. (1 point)

This is the output that should come

JavaScript

lottohelper_using_getopt Module

JavaScript

I would be grateful if someone explains how to go about the question and solve it

Advertisement

Answer

This should do it. I added some comments for additional info, search them in your favourite engine if you don’t already know how they work.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement