#!/usr/bin/python3

import cgi, os, html

def input_get():

    # get values from the html
    
    form = cgi.FieldStorage()
    
    weedcost_ = form["weedcost"].value
    
    batchgrams_ = form["batchgrams"].value
    
    batchbrownies_ = form["batchbrownies"].value
    
    brownies_ = form["brownies"].value

    return [float(weedcost_), float(batchgrams_), float(batchbrownies_), float(brownies_)]



def calculate(weedcost__, batchgrams__, batchbrownies__, brownies__):
    
    # the actual calculation

    return 16 * weedcost__ * batchgrams__ * brownies__ / (453.59237 * batchbrownies__)
    
    
    
def display(finalcost, input_ints_):
    
    # print the html output
    
    print(
        "<html>",
        
        "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
    
        "<head>",
        
        "<title> Calculation result </title>",
        
        "<link rel = \"stylesheet\" href = \"brownies.css\">",
        
        "</head>",
    
        "<body>",
    
        "<h3> Result </h3>",
        
        "<p> &pound", input_ints_[0], "per oz weed <br>",
        
        input_ints_[1], "g weed per batch <br>",
        
        int(input_ints_[2]), "brownies per batch <br>",
        
        int(input_ints_[3]), "brownies sold </p>",
        
        "<p> You should sell", int(input_ints_[3]), "brownies for &pound", round(finalcost, 2), "</p>",
    
        "</body>",
    
        "</html>"
        )



def maincode():
    
    print("Content-type: text/html\n\n<!doctype html>")

    input_ints = input_get()
    
    result = calculate(input_ints[0], input_ints[1], input_ints[2], input_ints[3])

    display(result, input_ints)
    


# main code
maincode()