python作业_01.06

 1. 题目描述
现在IPV4下用一个32位无符号整数来表示,一般用点分方式来显示,点将IP地址分成4个部分,每个部分为8位,表示成一个无符号整数(因
此不需要用正号出现),如10.137.17.1,是我们非常熟悉的IP地址,一个IP地址串中没有空格出现(因为要表示成一个32数字)。
现在需要你用程序来判断IP是否合法。

输入描述:输入一个ip地址
输出描述:返回判断的结果YES or NO


示例1
输入: 10.138.15.1
输出: YES

代码实现:


注意:在判断大小时要注意数据类型的一致性,例如将i转化为整形再比较


#2. 题目描述
1 总体说明
考生需要模拟实现一个简单的自动售货系统,实现投币、购买商品、退币、查询库存商品及存钱盒信息的功能。
系统初始化时自动售货机中商品为6种商品,商品的单价自定义,存钱盒内放置1元、2元、5元、10元钱币,商品数量和钱币张数通过初始化>命令设置。
商品:每种商品包含商品名称、单价、数量三种属性,其中商品名不重复。不能修改商品名称和单价,初始化命令设置商品数量。

代码实现:

#coding:utf-8
info="""
=============自动售卖饮料系统===========
    1.购买商品
    2.查询存钱盒信息
    3.退出
====================================
请选择:
"""
goods={"1.雪碧":{"price/":3,"number":10},
       "2.可乐":{"price/":3,"number":10},
       "3.水蜜桃":{"price/":2,"number":10}}
many_box={"1":5,"2":5,"5":5,"10":5}
while 1:
       choice=raw_input(info)
       if choice=="2":
              for i,j in many_box.items():
                     print i,j
       elif choice=="1":
              while 1:
                     print goods
                     name_1=input("请选择种类:")
                     if name_1==1:
                            name="1.雪碧"
                     elif name_1==2:
                            name="2.可乐"
                     elif name_1==3:
                            name=="3.水蜜桃"
                     else:
                            print "请正确选择"
                            break
                     number=input("请选择数量:")
                     if not number<=goods[name]["number"]:
                            print "数量不足!"
                            break
                     else:
                            while 1:
                                   many=input("请投币:")
                                   if many>10:
                                          print "只收取125元和10"
                                          break
                                   else:
                                          if many<goods[name]["price/"]*number:
                                                 print "金额不足"
                                                 continue
                                          else:
                                                 if many==5:
                                                        many_box["5"]+1
                                                 elif many==10:
                                                        many_box["10"]+1
                                                        goods[name]["number"]-=number
                                                        many_1=goods[name]["price/"]*number
                                                        black=many-many_1
                                                        b=black/5
                                                        c=black%5/2
                                                        d=black%5%2
                                                        print "返回1%d张,2%d张,5%d"%(b,c,d)
                                                        print "购买成功"
                                                        break



       elif choice=="3":
              exit()
       else:
              print "选择错误,请重新选择..."


# 3. ATM
            ATM柜员机管理系统d
实现功能:
    1. 当用户在登陆界面输入卡号和密码能登陆;
    2. 实现开户功能;
    3. 与机器交互实现取款, 存款, 转账, 查询余额,
       冻结账户, 修改密码等功能;

#coding:utf-8
user={"student":{"password":"student","check":1000,"status":1}}
info="""
        ATM柜员机管理系统
1.用户登录
2.注册用户
3.退出
请选择:
"""
info_1="""
        用户操作系统
1.取款
2.存款
3.转账
4.查询余额
5.修改密码
6.冻结账户
7.退出
请选择:
"""
def user_Login():
    while 1:
        print "     用户登陆系统"
        name=raw_input("name:")
        if name not in user:
            print "该用户不存在!请重新输入"
        else:
            if user[name]["status"]!=1:
                print "账户已被冻结"
                break
            else:
                password=raw_input("password:")
                if user[name]["password"]!=password:
                    print "密码错误..."
                else:
                    print "登陆成功!"
                    while 1:
                        choice_1=raw_input(info_1)
                        if choice_1=="1":
                            while True:
                                many = input("请输入取款金额:")
                                if many>user[name]["check"]:
                                    print "余额不足..."
                                else:
                                    user[name]["check"]-=many
                                    print "取款成功!"
                                    break
                        elif choice_1=="2":
                            many = input("请输入存款金额:")
                            user[name]["check"]+= many
                            print "存款成功!"
                        elif choice_1 == "3":
                            name_1=raw_input("请输入转入账户:")
                            if name_1 in user:
                                many=input("请输入转账金额:")
                                if user[name]["check"]<many:
                                    print "余额不足"
                                else:
                                    user[name]["check"]-=many
                                    user[name_1]["check"]+=many
                                    print "转账成功"
                        elif choice_1=="4":
                            print "可用余额为%d"%(user[name]["check"])
                        elif choice_1=="6":
                            user[name]["status"]=0
                            print "冻结账户成功"
                            break
                        elif choice_1=="5":
                            password_1=raw_input("new_password:")
                            password_2=raw_input("repeat new_password:")
                            if password_1!=password_2:
                                print "密码输入错误"
                            else:
                                user[name]["password"]=password_1
                                print "修改成功"
                                break
                        elif choice_1=="7":
                            exit()
                        else:
                            print "请重新选择..."
def user_register():
    print "     用户注册系统"
    name=raw_input("name:")
    if name in user:
        print "该用户名已存在"
    else:
        password=raw_input("password:")
        user[name]={"password":password,"check":0,"status":1}
        print "注册成功!"
def main():
    while 1:
        choice=raw_input(info)
        if choice=="1":
            user_Login()
        elif choice=="2":
            user_register()
        elif choice=="3":
            exit()
        else:
            print "选择错误,请重新选择..."
main()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值