1. python英里和公里的转换
def print_menu():
print('1. Kilometers to Miles')
print('2. Miles to kilometers')
def km_miles():
km = float(input('Enter distance in kilometers: '))
miles = km / 1.609
print('Distance in miles: {0}'.format(miles))
def miles_km():
miles = float(input('Enter distance in miles: '))
km = miles * 1.609
print('Distance in kilometers: {0}'.format(km))
if __name__ == '__main__':
print_menu()
choice = input('Which conversion would you like to do?:')
if choice == '1':
km_miles()
if choice == '2':
miles_km()
2. 用python写一个 点餐代码--急急急 !!! 希望高人帮忙!
#coding:utf-8
menu={
'1':dict(name='草莓冰淇淋',price=20),
'2':dict(name='香草冰淇淋',price=10),
'3':dict(name='香蕉冰淇淋',price=15),
'5':dict(name='巧克力冰淇淋',price=30),
}
defshowmenu(menu):
fork,iteminsorted(menu.items()):
print"%(key)s:%(name)s价格%(price).2f"%dict(key=k,**item)
defmenuchoice(menu):
whileTrue:
showmenu(menu)
c=raw_input("YourChoice('.'forend):")
ifc=='.':
break
else:
yieldmenu.get(c)
customerchoice=filter(None,menuchoice(menu))
print"Total:%.2f"%sum(map(lambdax:x["price"],customerchoice))