1. 题目描述
现在IPV4下用一个32位无符号整数来表示,一般用点分方式来显示,点将IP地址分成4个部分,每个部分为8位,表示成一个无符号整数(因此不需要用正号出现),如10.137.17.1,是我们非常熟悉的IP地址,一个IP地址串中没有空格出现(因为要表示成一个32数字)。
现在需要你用程序来判断IP是否合法。
输入描述:输入一个ip地址
输出描述:返回判断的结果YES or NO
示例1
输入: 10.138.15.1
输出: YES
#!/usr/bin/env python
#coding:utf-8
ip = raw_input("please input an ip:")
ip_item_list = ip.split(".")
if len(ip_item_list) != 4:
print "NO"
else :
for item in ip_item_list:
if not 0 <= int(item) <256 :
print "NO"
break
else :
print "YES"
- 题目描述
1 总体说明
考生需要模拟实现一个简单的自动售货系统,实现投币、购买商品、退币、查询库存商品及存钱盒信息的功能。
系统初始化时自动售货机中商品为6种商品,商品的单价自定义,存钱盒内放置1元、2元、5元、10元钱币,商品数量和钱币张数通过初始化命令设置。
商品:每种商品包含商品名称、单价、数量三种属性,其中商品名不重复。不能修改商品名称和单价,初始化命令设置商#品数量。
#!/usr/bin/env python
#coding:utf-8
rmb = {"10" : 10,
"5" : 10 ,
"2" : 10 ,
"1" : 10
}
goods = {"cocacola":{"count":10,
"price":3},
"pepsi cola":{"count":10,
"price":3},
"black tea":{"count":10,
"price":3},
"water":{"count":10,
"price":3},
"milk":{"count":10,
"price":3},
"juice":{"count":10,
"price":3}
}
def buy():
good=raw_input("please enter what you want:")
if good not in goods:
print "Don't have this good!"
elif goods[good]["count"] == 0:
print "sell out!"
else :
money1 = input("please insert coins:")
while 0 < money1 < goods[good]["price"] :
print "NOT enough!"
money2 = input("please insert coins:")
money1 = money1 + money2
if money2 == 0 :
print money1
break
else :
money3 = money1 - goods[good]["price"]
while money3 > 10 and rmb["10"] > 0:
money3 = money3 - 10
rmb["10"] = rmb["10"] - 1
print "10"
while money3 >= 5 and rmb["5"] > 0:
money3 = money3 - 5
rmb["5"] = rmb["5"] -1
print "5"
while money3 >= 2 and rmb["2"] > 0:
money3 = money3 - 2
print "2"
rmb["2"] = rmb["2"] - 1
while money3 >= 1 and rmb["1"] > 0:
money3 = money3 -1
rmb["1"] = rmb["1"] -1
print "1"
if money3 > 0:
print "please call 11111111"
else :
goods[good]["count"] = goods[good]["count"]- 1
def initial():
rmb["10"] = input("please input the count of 10 yuan :")
rmb["5"] = input("please input the count of 5 yuan :")
rmb["2"] = input("please input the count of 2 yuan :")
rmb["1"] = input("please input the count of 1 yuan :")
goods["cocacola"]["count"] = input("please input the count of cocacola:")
goods["pepsi cola"]["count"] = input("please input the count of pepsi cola:")
goods["water"]["count"] = input("please input the count of water:")
goods["milk"]["count"] = input("please input the count of milk:")
goods["juice"]["count"] = input("please input the count of juice:")
goods["black tea"]["count"] = input("please input the count of black tea:")
def main() :
initial()
while 1 :
print goods
buy()
main()