Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array.
Each number should be displayed as a list, the numbers should be generated when a button is clicked and then the list should be shown on the page
Please try not to change the original lottery code that can be used to create web program with Flask. Please provide the basic html as well. Screenshots of output. Indentation please. There should be a button where a user presses submit to generate the lottery numbers on the same web page.
Basic Html code is also there to use with program code. import random lottery_numbers=[0]*9 # create an array with 9 elements # iterate over each element in the array for i in range(len(lottery_numbers)): lottery_numbers[i] = random.randint(0,42) # loop to display the content of the array for num in enumerate(lottery_numbers,start=1): print('Lottery #{}: {}'.format(num[0],num[1]))
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<head>
<title></title>
</head>
<body>
<h1></h1>
<form action="#" method="POST">
<input type="text"
name="newTask" />
<button
type="submit">Add</button>
</form>
<ul>
{% for task in task %}
<li>{{task}}</li>
{% endfor %}
</ul>
</body>
</html>
Find the code for the above question below, read the
comments provided in the code for better understanding. If found
helpful please do upvote this.
For this you need the correct folder structure. Read the steps carefully.
The folder structure wil be somthing like this.
inside templates folder will be index.html.
app.py code
import flask#import flask import random#import random #create a flask app app = flask.Flask(__name__) #this will be called when user presses teh submit button #the method is post as mentioned in html file @app.route('/submit', methods=[ 'POST']) def generate(): lottery_numbers = [0] * 9 # create an array with 9 elements # iterate over each element in the array for i in range(len(lottery_numbers)): lottery_numbers[i] = random.randint(0, 42) # loop to display the content of the array for num in enumerate(lottery_numbers, start=1): print('Lottery #{}: {}'.format(num[0], num[1])) #render teh html file , this time pass the lottery numbers return flask.render_template('index.html',task=lottery_numbers) #this will be called when we visit the index page @app.route('/') def index(): #render teh html file return flask.render_template('index.html') #run the flask app app.run()
Screenshot of app.py
index.html code
<!DOCTYPE html> <head> <title></title> </head> <body> <h1></h1> <!-- call the submit route described in app.py--> <form action="submit" method="POST"> <input type="text" name="newTask" /> <button type="submit">Add</button> </form> <!-- display the random numbers passes--> <ul> {% for task in task %} <li>{{task}}</li> {% endfor %} </ul> </body> </html>
Output
Run the app.py , something like below will show up ,
open the link in any browser
, press the button
Design a program using Python and using from flask Import flask that generates a lottery number...
C++ exercise: Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element. (Use the random function that was discussed in Chapter 6.) Then write another loop that displays the contents of the array.
NEED HELP DIRECTIONS: Notice that there is one input area and two buttons There is a place in the HTML reserved for < li > elements under the heading “Shopping List” Write a javascript program that will cause whatever the user inputs to be placed in a newly -created < li > tag and the tag placed inside the < ul > element whenever the user clicks the button Your program must not create any < li > tag is...
Modify an application that lets users add tasks to a list so the tasks can also be deleted when they’re completed. 1. In the HTML file, enclose the text for each of the three existing list items in a <p> element. Then, Add buttons like the ones shown above preceding the <p> elements. No ids or names are required for these buttons, but they should be assigned to the class named “delete”. 2. In the JavaScript file, modify the event...
<!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Date: Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hands-on Project 4-3</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 4-3 </h1> </header> <article> <div id="results"> <p id="resultsExpl"></p> <ul> <li id="item1"></li> <li id="item2"></li> <li id="item3"></li> <li id="item4"></li> <li id="item5"></li> </ul> </div> <form> <fieldset> <label for="placeBox" id="placeLabel"> Type the name of a place, then click Submit: </label> <input type="text" id="placeBox"...
PYTHON: Using Lists and Arrays! 3. Design a program that generates a seven-digit lottery number. The program should generate seven random numbers, each in the range of 0 through 9, and assign each number to a list element. (Random numbers were discussed in Chapter 5.) Then write another loop that displays the contents of the list.
In this problem, you will create a selectable “To Do” List. To add a task to this list, the user clicks the Add Task button and enters a description of the task. To delete a task from the list, the user selects the task and then clicks the Delete Task button. Open the HTML and JavaScript files provided as start-up files (index.html from within todo_list_Q.zip file). Then, review the HTML in this file. Note, within the div element, there is...
Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...
Javascript to edit a HTML file. Where to begin? <!doctype html> <html> <head> <meta charset="utf-8"> <title>TODO: Change The Title</title> </head> <body> <h1></h1> <p>First paragraph.</p> <p class="intro">Second <span>paragraph</span>.</p> <button id="start">Start</button> <main> </main> <!-- Test 6: DOM Programming You MAY consult the notes for week 7, but you MAY NOT discuss this test or your code with any other students. All work must be your own. Instructions: 1. Put all solution code in a file named solution.js. When you upload your solution to...
Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements: The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...
Total Sales Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. Need: variable lists, IPO Chart, pseudocode, Flowchart, and working Python code. 2. Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop...