[英]Python - Display Entered Information and Average
我知道標題並沒有多大幫助,但我真的不知道該為它寫些什么。 我的代碼應該做的是顯示一個頁面,其中包含輸入名稱和分數的輸入,然后通過library.py頁面中的某些功能,使其像高分板一樣從高到低列出它們。 然后在底部需要有一個平均分數。 但是我對此很難過。 首先,當我輸入信息時,它甚至都不會注冊它。 我在表單標簽上使用了GET方法,但信息無處不在。 應該至少進入網址欄。 但事實並非如此。 而且我什至不知道該如何處理庫頁面。 只是一團糟。 如果可以幫助我,謝謝。
main.py
import webapp2
#from library import GameInfo
from page import FormsPage, ResultsPage
class MainHandler(webapp2.RequestHandler):
def get(self):
f = FormsPage()
r = ResultsPage()
if self.request.GET:
user = self.request.GET['name']
score = self.request.GET['score']
self.response.write(r.rbegin + r.rbody)
else:
self.response.write(f.fbegin + f.fbody + f.fformbox + f.fforms)
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
庫.py
class ScoresList():
def __init__(self):
self.name = ''
self.__score = 0
#keeps memory of all the scores intered
def list_scores(self, s):
self.__score_array.append(s)
def make_list(self):
output = ''
for score in self.__score_array:
output += name + score
return output
class Average():
pass
page.py
class FormsPage(object):
fbegin = '''<!DOCTYPE HTML>
<html>
<head>
<title>Post Your High Scores</title>
<link href="/css/style.css" rel="stylesheet" type="text/css"/>
</head>'''
fbody = '''<body>
<h1>Submit Your High Scores</h1>'''
fformbox = '''<div> '''
fforms = '''<form method="GET">
<label>Name: </label><input type="text" name"name"/>
<label>Score: </label><input type="text" name"score"/></br>
<label>Name: </label><input type="text" name"name"/>
<label>Score: </label><input type="text" name"score"/></br>
<label>Name: </label><input type="text" name"name"/>
<label>Score: </label><input type="text" name"score"/></br>
<label>Name: </label><input type="text" name"name"/>
<label>Score: </label><input type="text" name"score"/></br>
<label>Name: </label><input type="text" name"name"/>
<label>Score: </label><input type="text" name"score"/></br>
<input type="submit" value="Enter Scores" />
</form>
</body>
</html>'''
class ResultsPage(object):
rbegin = '''<!DOCTYPE HTML>
<html>
<head>
<title>Here are Your High Scores</title>
<link css/style.css/>
</head>'''
rbody = '''<body>
<div class="scoreboard">
<h1>High Scores</h1>
</div>
</body>
</html>'''
您忘記了name
屬性的等號。 另外,將多個輸入同名會產生沖突。
嘗試name="name1"
等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.