Advertisement

Python课程中剪刀石头布游戏的测试和设计

阅读量:

异常复杂的剪刀石头布游戏规则,令人感到极为繁琐。

复制代码
    import random
    items=['rock','paper','scissors']										#电脑可能出的:剪刀,石头或者布
    winrounds=0;															#初始化赢的局数
    loserounds=0;															#初始化输的局数
    ifContinue='yes'														#用于结束后判断是否再来一局
    
    while ifContinue=='yes':												#是yes的情况下运行
    
    	for rounds in range(1,4) :											#一共3局
    		print("1.rock 2.paper 3.scissors.\ninput number:")				
    		my=int(input())													#从键盘读取用户输入的数字,代表剪刀石头或者布
    		bot=random.choice(items);										#电脑随机出
    		if my==1 and bot=='scissors':									#下面是所有输赢情况,写的有点太繁琐,不知道日后会不会想出更加简洁的写法

全部评论 (0)

还没有任何评论哟~