def show_question(): random_hero = random.choice(list(character_images.keys())) heroes = character_images.keys() return render_template('answer.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info)
def show_answer(): random_hero = random.choice(list(character_images.keys())) answer = request.form['answer'] previous_hero = request.form['random_hero'] previous_hero_real_name = character_info[previous_hero]['Real Name'] right_answers = int(request.form['correct_count']) if right_answers > 0: print(score_counter(right_answers)) return render_template('answer.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info, answer=answer, previous_hero=previous_hero, real_name=real_name, previous_hero_real_name=previous_hero_real_name, right_answers=right_answers)
def show_answer(): global right_answers # python 3 needs global keyword to recognize variables global wrong_answers random_hero = random.choice(list(character_images.keys())) while True: random_hero = random.choice(heroes) if random_hero not in right_answers: play_again = '' break answer = request.form['answer'] previous_hero = request.form['random_hero'] previous_hero_real_name = character_info[previous_hero]['Real Name'] if answer == previous_hero_real_name: # right_answers += 1 right_answers.add(random_hero) else: # wrong_answers += 1 wrong_answers.add(random_hero) return render_template('answer.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info, answer=answer, previous_hero=previous_hero, real_name=real_name, previous_hero_real_name=previous_hero_real_name, right_answers=len(right_answers), wrong_answers=len(wrong_answers), total=len(heroes))
def index(): heroes = character_images.keys() return render_template('index.html', heroes=heroes, character_info=character_info, character_images=character_images)
def show_question(): heroes = character_images.keys() return render_template('question.html', heroes=heroes, character_info=character_info, character_images=character_images)
from flask import Flask, render_template, request from werkzeug.debug import DebuggedApplication from marvel_characters import character_info, character_images import decendents_characters import random app = Flask(__name__) app.wsgi_app = DebuggedApplication(app.wsgi_app, True) heroes = list(character_images.keys()) real_name = sorted(character_images.values()) right_answers = set() @app.route('/') def index(): return render_template('index.html', heroes=heroes, character_info=character_info, character_images=character_images) @app.route('/question') def show_question(): random_hero = random.choice(list(character_images.keys())) heroes = character_images.keys() return render_template('answer.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info)
from flask import Flask, render_template, request from werkzeug.debug import DebuggedApplication from marvel_characters import character_info, character_images import random app = Flask(__name__) app.wsgi_app = DebuggedApplication(app.wsgi_app, True) heroes = character_images.keys() real_name = character_images.values() def score_counter(count): if count != 0: count = count + 1 else: count = count + 0 return count # from jinja2 import Template # t = '''{% set correct_count=correct_count or 0 %}Count= {{ correct_count }}''' # template = Template(t) # print(template.render(correct_count=1)) # print(template.render()) @app.route('/') def index(): return render_template('index.html', heroes=heroes, character_info=character_info, character_images=character_images) @app.route('/question')
def show_answer(): random_hero = random.choice(list(character_images.keys())) answer = request.form['answer'] previous_hero = request.form['random_hero'] previous_hero_real_name = character_info[previous_hero]['Real Name'] return render_template('index.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info, answer=answer, previous_hero=previous_hero, real_name=real_name, previous_hero_real_name=previous_hero_real_name)
from flask import Flask, render_template, request from werkzeug.debug import DebuggedApplication from marvel_characters import character_info, character_images import random app = Flask(__name__) app.wsgi_app = DebuggedApplication(app.wsgi_app, True) heroes = character_images.keys() real_name = character_images.values() @app.route('/') @app.route('/question') def show_question(): random_hero = random.choice(list(character_images.keys())) heroes = character_images.keys() return render_template('index.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info) @app.route('/answer', methods=['POST']) def show_answer(): random_hero = random.choice(list(character_images.keys())) answer = request.form['answer'] previous_hero = request.form['random_hero'] previous_hero_real_name = character_info[previous_hero]['Real Name'] return render_template('index.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info, answer=answer, previous_hero=previous_hero, real_name=real_name, previous_hero_real_name=previous_hero_real_name) if __name__ == "__main__": app.config['TRAP_BAD_REQUEST_ERRORS'] = True
def index(): random_hero = random.choice(list(character_images.keys())) heroes = character_images.keys() return render_template('index.html', random_hero=random_hero, character_images=character_images, heroes=heroes, character_info=character_info)