python 输入输出转web_把用户输入的python函数转换成web应用程序?

好吧,所以我已经编写了一点代码,我试图理解所有的东西是如何组合在一起的。我在python和学习java方面都很有效率。参加了网络开发课程,了解HTML,widgets,一点JS。我的问题。。。有没有可能用python创建一个hangman游戏,然后把它发布到web页面上?或者像那样的事情永远不会发生?那么web小部件是用什么制作的?在

像这个:

随机导入#随机导入#Author

#File name: Lab01.py

#Date: 1/30/2014

#Purpose: allow user to play the game of hangman

#inputs:none

#outputs: Text that resembles the game of hangman

def main():

wordList=["max","cat","basket","ship","earth","coat","ocean","beach"]#creates set of words for game to chose from

userAnswer=raw_input("Type 1 or any button to play, 2 to quit: ")

while userAnswer != "2":

theWord=wordList[random.randint(0,len(wordList)-1)]

theWordList=[]

brickDisplay=[]

letterList=[]

count=0#sets count to 0

statementCount=0#sets statement count to 0

for i in range (len(theWord)):

theWordList.append(theWord[i])#creates list of each character of the word

brickDisplay=[]

for i in range (len(theWordList)):

brickDisplay.append("-")#Creates the same number of underscores that there are letters in the word

print brickDisplayMaker(brickDisplay)

letterChoice=raw_input("Enter a letter: ")

conditionEnd=conditionChecker(statementCount)#updates conditionEnd

wordEnd=wordChecker(theWordList,brickDisplay)#updates wordEnd

while wordEnd != "stop" and conditionEnd != "stop":

while letterChoice in letterList: #Checks if letter has already been entered by user

print "You've already entered that"

letterChoice=raw_input("Enter a letter: ")

else:

letterList.append(letterChoice)

for i in range(len(theWordList)):

if theWordList[i]==letterChoice:

count=count+1#counts the number of times letterChoice was in the word

brickDisplay[i]=theWordList[i]

print brickDisplayMaker(brickDisplay)

if count==0:

statementCount=statementCount+1

statementProducer(statementCount,theWord)

conditionEnd=conditionChecker(statementCount)

wordEnd=wordChecker(theWordList,brickDisplay)

count=0

if wordEnd=="stop":

print "You've Won!"

elif conditionEnd=="stop":

print "You have lost, the word was "+theWord #lets user know what the word was

else:

letterChoice=raw_input("Enter a letter: ")

userAnswer=raw_input("Type 1 or any button to play, 2 to quit: ")

print "Thanks for playing" #exists main

#Purpose: Check if words are the same

#Inputs: theWordList, brickDisplay

#outputs: "stop" or "go"

def wordChecker(theWordList,brickDisplay):

count=0

for i in range(len(theWordList)):

if theWordList[i]!=brickDisplay[i]:

count=count+1

if count==0:

return "stop"

else:

return "go"

#Purpose: Check if statement count equals 6

#inputs: StatementCount

#outputs: "stop" or "go"

def conditionChecker(statementCount):

if statementCount==6:

return "stop"

else:

return "go"

#Purpose: Create the brickDisplay with spaces between the underscores

#Inputs: brickDisplay

#Outputs:bricksDisplay with spaces between the underscores

def brickDisplayMaker(brickDisplay):

officialBrickDisplay=""

for ndx in brickDisplay:

officialBrickDisplay=officialBrickDisplay+ndx+" "#creates new list with spaces between underscores

return officialBrickDisplay

#Purpose: Produces statement based on the statementCount

#Inputs: statementCount

#Outputs: Statement

def statementProducer(statementCount,theWord):

if statementCount ==1:

print "Draw body part: head"

elif statementCount==2:

print "Draw body part: body"

elif statementCount==3:

print "Draw body part: left arm"

elif statementCount==4:

print "Draw body part: right arm"

elif statementCount==5:

print "Draw body part: left leg"

else:

print "Draw body part: right leg"

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值