Re: [Tutor] Best way to write this countdown code

2019-01-12 Thread Alan Gauld via Tutor
On 12/01/2019 15:44, Joseph Gulizia wrote:
> I want to integrate the following working code into a website:

First thing to note is that web sites speak HTML, so anything
you output for display needs to be in HTML not plain text.
(Plain text will usually be understood by a browser but
will look terrible!)

The normal way to build a web app is to create an HTML template
file with place holders for the data. Then use Python (or any
other server language) to inject the data via some kind of
web framework. (Flask and Bottle are two simple Python examples)

An alternative technique involves writing the app in
JavaScript that executes on the browser. That means creating
an HTML file that either contains your app as embedded
JavaScript or putting your JavaScript code into a separate
file and importing it into the HTML. The latter approach
is preferred for industrial sites but the single file approach
is OK for small applications.

Looking at your code we can remove all the lines that
should be in your HTML file:

> beef_quantity = 28  ## Set before campaign starts.
  beef_choice = ""
> if beef_choice == 'Quarter_Beef':
> new_beef_quantity = beef_quantity - 1
> elif beef_choice == 'Half_Beef':
> new_beef_quantity = beef_quantity - 2
> else:
> new_beef_quantity = beef_quantity - 4

The setting of the data values into the HTML will
depend on your framework.

> My end goal (which I still have to figure out) is to have the customer
> click on three sections of radio buttons and enter two text fields
> which will then display in an alert box where they can click a button

That's all HTML function not Python or even JavaScript

> to send them to PayPal for payment.  

Sending to Paypal is a whole new ball game.
That requires quite a bit of extra work.

> the number of available beef will countdown as each order is placed
> until zero s available which will then display "Sold Out!"  Not sure
> if this is ALL python or part python and part javascript.

It could be either or both.
But given your need to send to Paypal I'd suggest you find
a framework and work in Python. (Especially since you seem
to know some Python)

You probably should read the section in my tutorial(or any other)
that covers web applications. It's in the last section starting
with the topic entitled "Working with the Web" and moving on
to "Using Web Application Frameworks"

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best way to write this countdown code

2019-01-12 Thread Steven D'Aprano
On Sat, Jan 12, 2019 at 09:44:21AM -0600, Joseph Gulizia wrote:
> Thanks in advance as I've gotten wordy.
> 
> I want to integrate the following working code into a website:
[...]

Start with a simpler question: how would you integrate *any* Python code 
into a website?

Few (i.e. no) browsers directly support Python. This is why nearly all 
client-side (running in the brower) web development is done in 
Javascript. Server-side code can be written in Python, or any other 
language (Perl and PHP are other common choices) but for code that runs 
in the browser, it is difficult to use anything but Javascript.

But all is not quite lost:

http://www.skulpt.org/

https://duckduckgo.com/?q=python+in+the+browser


Start by getting a simple "Hello World" type program running in the 
browser, and then move on to something more ambitious.


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Best way to write this countdown code

2019-01-12 Thread Joseph Gulizia
Thanks in advance as I've gotten wordy.

I want to integrate the following working code into a website:


beef_quantity = 28  ## Set before campaign starts.
print('Original Beef Quantity: ')  ## Displays the wording "Original
Beef Quantity: "
print (beef_quantity)  ## Displays the beef quantity before order

beef_choice = 'Quarter_Beef' ## Based on Customer's choice

if beef_choice == 'Quarter_Beef':
print('Quarter Beef selected')  ## Notice of beef quantity ordered
print('New Beef Quantity: ')  ## Displays the wording "New beef quantity: "
new_beef_quantity = beef_quantity - 1  ## Updates the beef
quantity after order
print(new_beef_quantity)  ## Displays the updated beef quantity after order
elif beef_choice == 'Half_Beef':
print('Half Beef selected')  ## Notice of beef quantity ordered
print('New Beef Quantity: ')  ## Displays the wording "New beef quantity: "
new_beef_quantity = beef_quantity - 2  ## Updates the beef
quantity after order
print(new_beef_quantity)  ## Displays the updated beef quantity after order
else:
print('Whole Beef selected')  ## Notice of beef quantity ordered
print('New Beef Quantity: ')  ## Displays the wording "New beef quantity: "
new_beef_quantity = beef_quantity - 4  ## Updates the beef
quantity after order
print(new_beef_quantity)  ## Displays the updated beef quantity after order

I also have two other similar code pieces (delivery.py and locker.py)
that I want to integrate, but I'll put them in other emails.

My end goal (which I still have to figure out) is to have the customer
click on three sections of radio buttons and enter two text fields
which will then display in an alert box where they can click a button
to send them to PayPal for payment.  The other part of this is that
the number of available beef will countdown as each order is placed
until zero s available which will then display "Sold Out!"  Not sure
if this is ALL python or part python and part javascript.

Again, Thank you.
Joe
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor