Beispiel #1
0
from flask import Flask, render_template, request, redirect
app_test = Flask(__name__)

app_test.vars={}

app_test.questions={}
app_test.questions['How many eyes do you have?']=('1','2','3')
app_test.questions['Which fruit do you like best?']=('banana','mango','pineapple')
app_test.questions['Do you like cupcakes?']=('yes','no','maybe')

app_test.nquestions=len(app_test.questions)

@app_test.route('/index_test',methods=['GET','POST'])
def index_test():
    nquestions=app_test.nquestions
    if request.method=='GET':
        return render_template('userinfo.html',num=nquestions)
    else:
        #request was a post
        app_test.vars['name']=request.form['name']
        app_test.vars['age']=request.form['age']

        f=open('%s_%s.txt'%(app_test.vars['name'],app_test.vars['age']),'w')
        f.write('Name: %s\n'%(app_test.vars['name']))
        f.write('Age: %s\n\n'%(app_test.vars['age']))
        f.close()

        return redirect('/main_test')

@app_test.route('/main_test')
Beispiel #2
0
from flask import Flask, render_template, request, redirect
app_lulu = Flask(__name__)

app_lulu.vars = {}

app_lulu.questions = {}
app_lulu.questions['How many eyes do you have?'] = ('1', '2', '3')
app_lulu.questions['Which fruit do you like best?'] = ('banana', 'mango',
                                                       'pineapple')
app_lulu.questions['Do you like cupcakes?'] = ('yes', 'no', 'maybe')

app_lulu.nquestions = len(app_lulu.questions)
#should be 3


@app_lulu.route('/index_lulu', methods=['GET', 'POST'])
def index_lulu():
    nquestions = app_lulu.nquestions
    if request.method == 'GET':
        return render_template('userinfo_lulu.html', num=nquestions)
    else:
        #request was a POST
        app_lulu.vars['name'] = request.form['name_lulu']
        app_lulu.vars['age'] = request.form['age_lulu']

        f = open('%s_%s.txt' % (app_lulu.vars['name'], app_lulu.vars['age']),
                 'w')
        f.write('Name: %s\n' % (app_lulu.vars['name']))
        f.write('Age: %s\n\n' % (app_lulu.vars['age']))
        f.close()
Beispiel #3
0
    },
    '7': {
        'tip': 'a[start:end] slicing means items start through end-1',
        'answer': '__floordiv__()',
        'question': 'Which function overloads the // operator?',
        'options':
        ['__truediv__()', '__radd__', '__floordiv__()', '__ceildiv__()']
    }
}
#
py_summary = {}
py_summary["correct"] = []
py_summary["wrong"] = []
py_summary["curretq"] = 1
#
app.nquestions = len(questions)


#
# options to the questions can be shuffled
#
# for item in questions.keys():
# shuffle(questions[item]['options'])
#
#
# Route for the URL /python accepting GET and POST methods
# We are using session variables to keep track of the current question
# the user is in and show him just that question even if he reloads the page
# or opens the page in a new tab.
@app.route('/python', methods=['GET', 'POST'])
def index():
Beispiel #4
0
from flask import Flask, render_template, request, redirect
testapp = Flask(__name__)

testapp.vars={}

testapp.questions={}
testapp.questions['question']=('moo','poo','goo')
testapp.questions['Which fruit do you like best?']=('banana','mango','pineapple')
testapp.questions['Do you like cupcakes?']=('yes','no','maybe')
testapp.nquestions=len(testapp.questions)

@testapp.route('/index', methods=['GET', 'POST'])
def index():
	nquestions=testapp.nquestions
	if request.method == 'GET':
		return render_template('userinfo.html', num=nquestions)
	else:
		#request is likely to be a post
		testapp.vars['name1'] = request.form['name']
		testapp.vars['age'] = request.form['age']
		testapp.vars['gender'] = request.form['gender']

		#write file containing user information
		f = open('%s_%s.txt'%(testapp.vars['name1'], testapp.vars['age']),'w')
		f.write('Name: %s\n'%(testapp.vars['name1']))
		f.write('Age: %s\n\n'%(testapp.vars['age']))
		f.write('Gender: %s\n'%(testapp.vars['gender']))
		f.close()
		
		return redirect('/main')
Beispiel #5
0
#!/usr/bin/python

from flask import Flask, render_template, request, redirect

app_ming = Flask(__name__)
app_ming.vars = {}

app_ming.questions = {}
app_ming.questions['How many eyes do you have?'] = ('1', '2', '3')
app_ming.questions['Which fruit do you like best?'] = ('banana', 'apple',
                                                       'orange')
app_ming.questions['Do you like cupcakes'] = ('Yes', 'No', 'Maybe')

app_ming.nquestions = len(app_ming.questions)


@app_ming.route('/index_ming', methods=['GET', 'POST'])
def index_ming():
    nquestions = app_ming.nquestions
    if request.method == 'GET':
        return render_template('userinfo_ming.html', num=nquestions)
    else:
        app_ming.vars['name'] = request.form['name_ming']
        app_ming.vars['age'] = request.form['age_ming']

        f = open('%s_%s.txt' % (app_ming.vars['name'], app_ming.vars['age']),
                 'w')
        f.write('Name:%s\n' % (app_ming.vars['name']))
        f.write('Age:%s\n\n' % (app_ming.vars['age']))
        f.close()
        return redirect('/main_ming')
from flask import Flask, render_template, request, redirect
app_lulu = Flask(__name__)


app_lulu.vars={}


app_lulu.questions={}
app_lulu.questions['How many eyes do you have?']=('1','2','3')
app_lulu.questions['Which fruit do you like best?']=('banana','mango','pineapple')
app_lulu.questions['Do you like cupcakes?']=('yes','no','maybe')


app_lulu.nquestions=len(app_lulu.questions)
# should be 3


@app_lulu.route('/index_lulu', methods=['GET', 'POST'])
def index_lulu():
	nquestions = app_lulu.nquestions
	if request.method == 'GET':
		return render_template('userinfo_lulu.html', num=nquestions)
	else:
		# request was a POST
		app_lulu.vars['name'] = request.form['name_lulu']
		app_lulu.vars['age'] = request.form['age_lulu']
		
		f = open('%s_%s.txt'%(app_lulu.vars['name'],app_lulu.vars['age']),'w')
		f.write('Name: %s\n'%(app_lulu.vars['name']))
		f.write('Age: %s\n\n'%(app_lulu.vars['age']))
		f.close()
Beispiel #7
0
from flask import Flask, render_template, request, redirect
app = Flask(__name__)
#test
app.vars = {}

app.questions = {}
app.questions['How many eyes do you have?'] = ('1','2','3')
app.questions['Which fruit do you like best?'] = ('banana','mango','pineapple')
app.questions['Do you like cupcakes?'] = ('yes','no','maybe')

app.nquestions = len(app.questions)

@app.route('/index', methods=['GET','POST'])
def index():
	nquestions = app.nquestions
	if request.method == 'GET':
		return render_template('userinfo_lulu.html',num=nquestions)
		
	else:
		#request was a POST
		app.vars['name'] = request.form['name']
		app.vars['age'] = request.form['age']
		
		f = open('%s_%s.txt' % (app.vars['name'], app.vars['age']),'w')
		f.write('Name: %s\n' % (app.vars['name']))
		f.write('Age: %s\n\n' % (app.vars['age']))
		f.close()
		
		return redirect('/main')
	
@app.route('/main')
Beispiel #8
0
from flask import Flask, render_template, request, redirect
app = Flask(__name__)
app.vars = {}

app.questions = {}
app.questions['How many eyes do you have?'] = ('1', '2', '3')
app.questions['Which fruit do you like best?'] = ('banana', 'mango',
                                                  'pineapple')
app.questions['Do you like cupcakes?'] = ('yes', 'no', 'maybe')
app.nquestions = len(app.questions)


@app.route('/')
@app.route('/index', methods=['GET', 'POST'])
def index_method():
    nquestions = app.nquestions
    if request.method == 'GET':
        return render_template('userinfo.html', num=nquestions)
    else:
        #request was a POST
        app.vars['name'] = request.form['name_lulu']
        app.vars['age'] = request.form['age_lulu']

        f = open('%s_%s.txt' % (app.vars['name'], app.vars['age']), 'w')
        f.write('Name: %s\n' % (app.vars['name']))
        f.write('Age: %s\n\n' % (app.vars['age']))
        f.close()

        return redirect('/main_lulu')

Beispiel #9
0
from flask import Flask, render_template, request, redirect
testapp = Flask(__name__)

testapp.vars = {}

testapp.questions = {}
testapp.questions['question'] = ('moo', 'poo', 'goo')
testapp.questions['Which fruit do you like best?'] = ('banana', 'mango',
                                                      'pineapple')
testapp.questions['Do you like cupcakes?'] = ('yes', 'no', 'maybe')
testapp.nquestions = len(testapp.questions)


@testapp.route('/index', methods=['GET', 'POST'])
def index():
    nquestions = testapp.nquestions
    if request.method == 'GET':
        return render_template('userinfo.html', num=nquestions)
    else:
        #request is likely to be a post
        testapp.vars['name1'] = request.form['name']
        testapp.vars['age'] = request.form['age']
        testapp.vars['gender'] = request.form['gender']

        #write file containing user information
        f = open('%s_%s.txt' % (testapp.vars['name1'], testapp.vars['age']),
                 'w')
        f.write('Name: %s\n' % (testapp.vars['name1']))
        f.write('Age: %s\n\n' % (testapp.vars['age']))
        f.write('Gender: %s\n' % (testapp.vars['gender']))
        f.close()
# The object Flask() allows setting dictionaries to collect information from the user
# We set an empty dictonary that will collect name and age of user.
app_simpleApp.vars={}

# We set another dictionary for the questions asked in the form that will be displayed 
# in the web application
app_simpleApp.questions={}

# We populate the dictionary with questions and options
app_simpleApp.questions['How many eyes do you have?']=('1','2','3')
app_simpleApp.questions['Which fruit do you like best?']=('banana','mango','pineapple')
app_simpleApp.questions['Do you like cupcakes?']=('yes','no','maybe')

# We get the number of questions from the length of the dictionary
app_simpleApp.nquestions=len(app_simpleApp.questions)


@app_simpleApp.route('/index_simpleApp',methods=['GET','POST'])
# The app will be launched at 127.0.0.1:5000/index_simpleApp
def index_simpleApp():

	"""
	This function displays the corresponding HTML page that presents
	the survey and its questions. It also stores the answers provided
	by the user into a txt file
	"""

	# The number questions, nquestions, is gotten from the previous
	# app_simpleApp.nquestions
	nquestions = app_simpleApp.nquestions
Beispiel #11
0
from flask import Flask, render_template, request, redirect
app_guvi = Flask(__name__)

app_guvi.vars = {}

app_guvi.questions = {}
app_guvi.questions['How many eyes do you have?'] = ('1', '2', '3')
app_guvi.questions['Which fruit do you like best?'] = ('banana', 'mango',
                                                       'pineapple')
app_guvi.questions['Do you like cupcakes?'] = ('yes', 'no', 'maybe')

app_guvi.nquestions = len(app_guvi.questions)
#should be 3


@app_guvi.route('/index_guvi', methods=['GET', 'POST'])
def index_guvi():
    nquestions = app_guvi.nquestions
    if request.method == 'GET':
        return render_template('userinfo_guvi.html', num=nquestions)
    else:
        #request was a POST
        app_guvi.vars['name'] = request.form['name_guvi']
        app_guvi.vars['age'] = request.form['age_guvi']

        f = open('%s_%s.txt' % (app_guvi.vars['name'], app_guvi.vars['age']),
                 'w')
        f.write('Name: %s\n' % (app_guvi.vars['name']))
        f.write('Age: %s\n\n' % (app_guvi.vars['age']))
        f.close()