python中制作一个猜拳小游戏(带有当前时间)

import time, random, sys

print("欢迎来到猜拳游戏!")
print(time.strftime('现在时间为:%Y-%m-%d %H:%M:%S'))
password = input('请输入密码:')
password1 = '123456'
while password != password1:
    print(time.strftime('现在时间为:%Y-%m-%d %H:%M:%S'))
    print('您的密码有误,请重新输入!')
    password = input('请输入密码:')
else:
    pass
    print('登录成功,可以进行猜拳游戏了!')
    print('==========================================================')  # 登陆系统模拟
manner1 = '石头'
manner2 = '剪刀'
manner3 = '布'
system = random.choice(['石头', '剪刀', '布'])  # 定义三个随机变量(石头 剪刀 布)
while True:                                    
    print('请进行猜拳!(按0退出游戏):')
    user = input('请输入你要选择出:石头or剪刀or布:')  # 用户输入(选择)
    if user == manner1 and system == '剪刀':         # 各个情况的结果
        print('你出的是石头,电脑出的是剪刀,你赢了!')
    elif user == manner1 and system == '石头':
        print('你出的是石头,电脑出的是石头,平局!')
    elif user == manner1 and system == '布':
        print('你出的是石头,电脑出的是布,你输了!')
    elif user == manner2 and system == '剪刀':
        print('你出的是剪刀,电脑出的是剪刀,平局!')
    elif user == manner2 and system == '布':
        print('你出的是剪刀,电脑出的是布,你赢了!')
    elif user == manner2 and system == '石头':
        print('你出的是剪刀,电脑出的是石头,你输了!')
    elif user == manner3 and system == '布':
        print('你出的是布,电脑出的是布,平局!')
    elif user == manner3 and system == '剪刀':
        print('你出的是布,电脑出的是剪刀,你输了!')
    elif user == manner3 and system == '石头':
        print('你出的是布,电脑出的是石头,你赢了!')
    else:
        break
if user == '0':
    sys.exit()     #退出程序

内含:系统随机变量,当前时间,程序退出,模拟系统登录等多种知识

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值