<jupyter_start><jupyter_text>Initial Examples  **1. Using the print statement and variables**The print statement is used to display any value or sentence that you assign. To print a statement, you write 'print' with parentheses containing the content. There are 3 ways to print information: with a string of characters, using variables, and a combination of string and variables. Note that in order to incorporate variables and a string of characters, there needs to be an 'f' in the parentheses and the variable has curly-cew brackets around the values.<jupyter_code>print("Hello World!")
champagne_bucket = 1
print(champagne_bucket)
champagne_bucket= 1
print(f"The volume of champagne: {champagne_bucket} liters")<jupyter_output><empty_output><jupyter_text>**2. Use of data types**We use different kinds of data types to suit our needs. Below mentioned are the 4 major data types.<jupyter_code>int_example = 10 // a positive or negative value with decimals
float_example = 1.592 // a positive or negative value with decimals
char_example = 'A' // a character
string_example = 'This is a sentence.' // a string of characters (we just shortform that to string) 

print(f"The value of example is {float_example}")<jupyter_output><empty_output><jupyter_text>**3. Conversion of data types**Upon conversion from float to integer type, the non-decimal part is taken as the integer. It does not follow the classic rounding-off theory<jupyter_code>converted_int = int(float_example)
print("Converted float_example to integer:",converted_int)
char_example = '123'
print("Converted char_example to integer:", int(char_example))<jupyter_output><empty_output><jupyter_text>**3. Use of Lists** ***Here we define the shopping list***Assume the shopping list contains our daily requirements. Here we maintain a list of items to be bought. We can add and remove items as required.<jupyter_code>list_example = ['eggs','potatoes','cereal']
print(list_example)<jupyter_output><empty_output><jupyter_text>***Let us add another item to the shopping list***<jupyter_code>list_example.append('bacon')
print(list_example)<jupyter_output><empty_output><jupyter_text>***Turns out we have eggs at home and we don't need it to be on the shopping list***<jupyter_code>list_example.remove('eggs')
print(list_example)<jupyter_output><empty_output><jupyter_text>**4. Use of Dictionaries** ***Here we define the dictionary, just like the real one and print the meaning of the word Noun***Dictionaries are analogous form of data storage. It contains one 'key' which is associated with a 'value'. The word here is the 'key' and the meaning of the word is 'value'.<jupyter_code>dict_example = {'Noun':'A word used to identify any of a class of people, places, or things ','Verb':'a word used to describe an action, state, or occurrence, and forming the main part of the predicate of a sentence, such as hear, become, happen.','Adjective':'A word naming an attribute of a noun, such as sweet, red, or technical'}
print(dict_example['Noun'])<jupyter_output><empty_output><jupyter_text>*Let us print the dictionary*<jupyter_code>print(dict_example)<jupyter_output><empty_output><jupyter_text>**5. Use of the if statement**We take the input form the user and place it in a variable called 'outside'. Based on what is contained in the variable 'outside', i.e. If the weather outside is hot, we print, I want a cold beverage, If the weather outside is cold, we print, I want a hot beverage.<jupyter_code>outside = input()
if outside == 'hot':
  print('I want a cold beverage')
elif outside == 'cold':
  print('I want a hot beverage')<jupyter_output><empty_output><jupyter_text>6. Use of loops **Here we let the loop run 10 times**'var' is the increment counter. In both the loop types, we allow the varibale 'var' to range from 0-9. The progression of the var variable is understood with the print statement.<jupyter_code>var = 0
while var<10:
  print(var)
  var = var+1
for var in range(0,10):
  print(var)<jupyter_output><empty_output><jupyter_text>**7. Use of functions**'def' is a keyword that starts of the definition of the function, 'add' is the name of the function, a and b are function parameters that will be operated on inside the function 'return' keyword sends the output onto where the function is called.<jupyter_code>def add(a,b):
  return a+b

sum = add(5,1)
print(sum)<jupyter_output><empty_output><jupyter_text>**8. Pip install example**We use the pip package to install the pandas, numpy and matplotlib librariesThe '!' symbol is used to tell the notebook to run a shell command<jupyter_code>!pip install pandas
!pip install numpy
!pip install matplotlib<jupyter_output><empty_output><jupyter_text>Flask App Example  ***Here we install the 'flask-ngrok' library which helps us create a server and deploy it on the ngrok platform***flask is a python library that is a basic backend framework. It allows the hosting of webapps with the help of a python code base.<jupyter_code>!pip install flask-ngrok<jupyter_output><empty_output><jupyter_text>***We download the repository containing the flask app code***<jupyter_code>!git clone https://github.com/H10AI/PythonCrashCourse-PizzaPricePrediction.git<jupyter_output><empty_output><jupyter_text>***Note***: 1.   Upload the 'index.html' and 'Pizza-Price.csv' files from the github link that was provided.2. Drag and drop 'Pizza-Price.csv' into the Files section of google colab.3.  In the Files section of Colab, right-click and create a new folder, name it 'templates'.4. Drag and drop the 'index.html' file into the templates folder.5. Continue to the next code snippet  ***Task 1: Write code to convert takka to CAD***<jupyter_code>def convert_to_cad(price):
    #add conversion code here
    return price<jupyter_output><empty_output><jupyter_text>***The web app is hosted on the ngrok platform, click the ngrok link to interact with the web app***<jupyter_code>from flask import Flask, request, render_template
import pickle
import numpy as np
from flask_ngrok import run_with_ngrok
filename = '/content/PythonCrashCourse-PizzaPricePrediction/pizza_price_final.sav'
app = Flask(__name__)
run_with_ngrok(app)

def get_pred_price(loaded_model,inch,restau,cheese,musroom,spicy):
    hotel={'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8,'I':9,'J':10,'K':11,'L':12,'M':13,'N':14,'O':15,'P':16,'Q':17,'R':18,'S':19,'T':20}
    param=[inch,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,cheese,musroom,spicy]
    if restau in hotel.keys():
        param[hotel[restau]]=1
    price=loaded_model.predict([np.array(param)])
    return price

loaded_model = pickle.load(open(filename, 'rb'))



predict = 0
restuarant = 'None'
yesno = {'yes':1,'no':0}
@app.route('/', methods=['POST','GET'])
def my_form_post():
    global predict
    global restuarant
    error = ""
    if request.method == 'GET':
        # Form being submitted; grab data from form.
        if request.args:
            size = request.args.get('Size')
            restuarant = request.args.get('Restuarant')
            extr_cheese = yesno[request.args.get('extr_cheese')]
            extr_mushroom = yesno[request.args.get('extr_mushroom')]
            extr_spicy = yesno[request.args.get('extr_spicy')]
        
        #print(size,restuarant,extr_cheese,extr_mushroom,extr_spicy
            price = get_pred_price(loaded_model,size,restuarant,extr_cheese,extr_mushroom,extr_spicy)
            predict = price[0]
            predict = convert_to_cad(price)
        print(predict)
    # Render the sign-up page
    return render_template('index.html', prediction_text='Price of the Pizza from Restaurant {} is $ {}'.format(restuarant,predict))

if __name__ == "__main__":
    app.run()<jupyter_output><empty_output><jupyter_text>Data Vizualisation<jupyter_code>from google.colab import files
files.upload()
import pandas as pd
from matplotlib import pyplot as plt
df = pd.read_csv('Pizza-Price.csv')
df
#Price vs Size

x = df[' Size by Inch']
y = df['Price']
plt.scatter(x,y)
plt.show()<jupyter_output><empty_output><jupyter_text>***Task 1: Display the scatter plot between Restaurants and Price***<jupyter_code>#your code here

plt.bar(x, y)
df_plot = df[['Restaurant','Extra Mushroom']]
df_plot.head()<jupyter_output><empty_output><jupyter_text>***Data manipulation using pandas and the if statement***<jupyter_code>#conversion of columns
counter=0
for value in df['Extra Mushroom']:
  if value == 'yes':
    df['Extra Mushroom'][counter] = 1
  else:
    df['Extra Mushroom'][counter] = 0
  counter+=1
df['Extra Mushroom']
    
#plot frequency
plt.hist(df['Extra Mushroom'], bins=10)
plt.gca().set(title='Frequency Histogram of Extra Mushroom', ylabel='Frequency');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11161022805805114, 'fraction_numerical': 0.012209168394379175, 'mean_word_length': 5.553207547169811, 'pattern_counts': {'":': 1, '<': 78, '<?xml version=': 0, '>': 77, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '611219', 'license': 'MIT', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2725, 'n_words': 913, 'path': 'flask_app_pizza.ipynb', 'repo_name': 'H10AI/Python_Workshop', 'size': '8682'}