莱斯大学Python课程Mini-project # 1- Rock-paper-scissors-lizard-Spock
来源:互联网 发布:手机视频剪辑合成软件 编辑:程序博客网 时间:2024/06/05 18:23
要求:https://class.coursera.org/interactivepython-004/human_grading/view/courses/972072/assessments/28/submissions
做得跟要求有点不同。现在已经是第四周了,我还只做了前两周的练习。本月内一定要追上进度。
# play Rock-paper-scissors-lizard-Spock game with computerimport mathimport randomimport simplegui#globalplayer_choice="choose one please"your_choice= "nono"message="start"comp_number=random.randrange(0, 5) # the first helper function,change the name to number,0 — rock,1 — Spock,2 — paper,3 — lizard,4 — scissorsdef name_to_number(name): if name=='rock': number = 0 elif name=='spock': number=1 elif name=='paper' : number=2 elif name=='lizard': number=3 elif name=='scissors': number=4 else: number=5 return number# the second helper function, converts a number in the range 0 to 4 into its corresponding name as a stringdef number_to_name(number): if number == 0: name='rock' elif number==1: name='spock' elif number==2 : name='paper' elif number==3 : name='lizard' elif number==4 : name ='scissors' else: name= 'unidentified number' return name#define an input handlerdef input_handler(text): global player_choice player_choice=text # define a handler to start new gamedef new_game(): global comp_number global your_choice comp_number=random.randrange(0, 5) # main function def compare(): global message player_number=name_to_number(player_choice) if player_number == 5: message= "start again !!!" elif (comp_number-player_number)%5 == 0 : message= "TIE" elif (comp_number-player_number)%5 == 1 : message= "you win" elif (comp_number-player_number)%5 == 2 : message= "you win, ok?" else: message= "computer wins" return message #define draw handlerdef draw(canvas): canvas.draw_text(compare(),[100,100],20,"White") #create the frameframe=simplegui.create_frame("little game",300,200) #register event handlerframe.set_draw_handler(draw) frame.add_input("input rock, or paper,or scissors,or lizard,or spock",input_handler,180) frame.add_button("new game",new_game,108) #start the gameframe.start()
0 0
- 莱斯大学Python课程Mini-project # 1- Rock-paper-scissors-lizard-Spock
- Interactive Python:Mini-project # 1 - Rock-paper-scissors-lizard-Spock
- Python Mini Project - Rock Paper Scissors Lizard Spock
- Mini-project # 1 - Rock-paper-scissors-lizard-Spock
- Mini-project # 1 - Rock-paper-scissors-lizard-Spock
- Mini-project # 1 - Rock-paper-scissors-lizard-Spock
- Mini-project description 1 - Rock-paper-scissors-lizard-Spock
- [Interactive Python] Rock-paper-scissors-lizard-Spock 游戏 Mini-project #1
- Python 8 - Rock-paper-scissors-lizard-spock
- 1 paper-rock-scissors-lizard-spock
- Rock-paper-scissors-lizard-Spock
- 作业week1 'Rock-paper-scissors-lizard-Spock'
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- (Rock, Paper, Scissors, Lizard and Spock)sheldon谢耳朵独创的剪刀,布,石头,蜥蜴,史波克 用代码实现
- IIPP迷你项目(一)“Rock-paper-scissor-lizard-Spock”
- 莱斯大学Python课程Mini-project#4 - "Pong"
- 莱斯大学Python课程Mini-project#5 - Memory
- Rock-Paper-Scissors
- 数组
- eclipse解决editor does not contain a main type的方法
- 第6周作业3-Fibonacci数列
- 多线程同步
- 骨架提取——Khalid Sheed的K3M算法
- 莱斯大学Python课程Mini-project # 1- Rock-paper-scissors-lizard-Spock
- ASIHTTPRequest下载地址和类库配置步骤
- CSS剪裁图像
- Time Allocation While programming
- FlexBuilder 快捷键
- 求解一道腾讯笔试题(帮帮忙)
- 使用code::blocks搭建objective-c的IDE开发环境 支持 @interface
- 遍历Map的四种方法
- 自制FFmpeg SDK并使用output_example测试