python小代码10(字典的创建与应用)

任务一:银行卡号生成器
任务内容:
现要求生成100个银行卡号,并初始化密码为000000”
程序编写要求:
➢卡号由6位组成,前3位是610后面的依次是
001,002,003…100
➢要求使用字典保存卡号及密码

代码如下:

list=[]
for i in range(610001,610101):
    list.append(str(i))
#print(list)
dict1=dict.fromkeys(list,'000000')
print("100个银行卡及密码如下所示:",end='')
print(dict1)

运行结果如下:

100个银行卡及密码如下所示:{'610001': '000000', '610002': '000000', '610003': '000000', '610004': '000000', '610005': '000000', '610006': '000000', '610007': '000000', '610008': '000000', '610009': '000000', '610010': '000000', '610011': '000000', '610012': '000000', '610013': '000000', '610014': '000000', '610015': '000000', '610016': '000000', '610017': '000000', '610018': '000000', '610019': '000000', '610020': '000000', '610021': '000000', '610022': '000000', '610023': '000000', '610024': '000000', '610025': '000000', '610026': '000000', '610027': '000000', '610028': '000000', '610029': '000000', '610030': '000000', '610031': '000000', '610032': '000000', '610033': '000000', '610034': '000000', '610035': '000000', '610036': '000000', '610037': '000000', '610038': '000000', '610039': '000000', '610040': '000000', '610041': '000000', '610042': '000000', '610043': '000000', '610044': '000000', '610045': '000000', '610046': '000000', '610047': '000000', '610048': '000000', '610049': '000000', '610050': '000000', '610051': '000000', '610052': '000000', '610053': '000000', '610054': '000000', '610055': '000000', '610056': '000000', '610057': '000000', '610058': '000000', '610059': '000000', '610060': '000000', '610061': '000000', '610062': '000000', '610063': '000000', '610064': '000000', '610065': '000000', '610066': '000000', '610067': '000000', '610068': '000000', '610069': '000000', '610070': '000000', '610071': '000000', '610072': '000000', '610073': '000000', '610074': '000000', '610075': '000000', '610076': '000000', '610077': '000000', '610078': '000000', '610079': '000000', '610080': '000000', '610081': '000000', '610082': '000000', '610083': '000000', '610084': '000000', '610085': '000000', '610086': '000000', '610087': '000000', '610088': '000000', '610089': '000000', '610090': '000000', '610091': '000000', '610092': '000000', '610093': '000000', '610094': '000000', '610095': '000000', '610096': '000000', '610097': '000000', '610098': '000000', '610099': '000000', '610100': '000000'}

任务二:超市售货统计程序
任务内容:某超市近三天的售货情况如下所示:
在这里插入图片描述
程序编写要求:
➢创建4个字典保存上表中的内容
➢按天求出当天的售货件数以及售货金额,输出如下图所示:
在这里插入图片描述

代码如下:

dict={1:'日期',2:'货品名称',3:'数量',4:'单价'}#存储列名
dict1={'11月24日':['牛奶','方便面','糖果'],'11月25日':['牛奶','咖啡','饼干','火腿肠'],'11月26日':['奶茶','牛奶','方便面']}#存储每天卖的货品名称
dict2={'牛奶':5.5,'方便面':4,'糖果':12,'咖啡':6,'饼干':6,'火腿肠':5,'奶茶':5,}#存储单价
dict3={'11月24日':{'牛奶':15,'方便面':25,'糖果':10},'11月25日':{'牛奶':25,'咖啡':5,'饼干':15,'火腿肠':10},
       '11月26日':{'奶茶':10,'牛奶':20,'方便面':15}}#存储每天卖出商品数量
#print(dict,"\n",dict1,"\n",dict2,"\n",dict3,"\n")
print("11月24日")
money=0
number=0
for i in range(len(dict1['11月24日'])):
    print("     ",end='')
    print(dict1['11月24日'][i],end='')
    print("     ", end='')
    print("数量:", end='')
    print(dict3['11月24日'][dict1['11月24日'][i]],end='')
    print("     ", end='')
    print("单价:%.1f"%(dict2[dict1['11月24日'][i]]))
    number+=dict3['11月24日'][dict1['11月24日'][i]]
    money+=(dict2[dict1['11月24日'][i]])*(dict3['11月24日'][dict1['11月24日'][i]])
print("     ", end='')
print("11月24日卖出货件%.0f件,小计%.1f元"%(number,money))

print("11月25日")
money=0
number=0
for i in range(len(dict1['11月25日'])):
    print("     ",end='')
    print(dict1['11月25日'][i],end='')
    print("     ", end='')
    print("数量:", end='')
    print(dict3['11月25日'][dict1['11月25日'][i]],end='')
    print("     ", end='')
    print("单价:%.1f"%(dict2[dict1['11月25日'][i]]))
    number+=dict3['11月25日'][dict1['11月25日'][i]]
    money+=(dict2[dict1['11月25日'][i]])*(dict3['11月25日'][dict1['11月25日'][i]])
print("     ", end='')
print("11月25日卖出货件%.0f件,小计%.1f元"%(number,money))

print("11月26日")
money=0
number=0
for i in range(len(dict1['11月26日'])):
    print("     ",end='')
    print(dict1['11月26日'][i],end='')
    print("     ", end='')
    print("数量:", end='')
    print(dict3['11月26日'][dict1['11月26日'][i]],end='')
    print("     ", end='')
    print("单价:%.1f"%(dict2[dict1['11月26日'][i]]))
    number+=dict3['11月26日'][dict1['11月26日'][i]]
    money+=(dict2[dict1['11月26日'][i]])*(dict3['11月26日'][dict1['11月26日'][i]])
print("     ", end='')
print("11月26日卖出货件%.0f件,小计%.1f元"%(number,money))

运行结果如下:

11月24日
     牛奶     数量:15     单价:5.5
     方便面     数量:25     单价:4.0
     糖果     数量:10     单价:12.0
     11月24日卖出货件50件,小计302.5元
11月25日
     牛奶     数量:25     单价:5.5
     咖啡     数量:5     单价:6.0
     饼干     数量:15     单价:6.0
     火腿肠     数量:10     单价:5.0
     11月25日卖出货件55件,小计307.5元
11月26日
     奶茶     数量:10     单价:5.0
     牛奶     数量:20     单价:5.5
     方便面     数量:15     单价:4.0
     11月26日卖出货件45件,小计220.0元

  • 11
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用 Appium 进行自动化测试时,可能需要获取应用的权限许可。以下是获取应用权限许可的 Python 代码示例: ``` from appium import webdriver from appium.webdriver.common.mobileby import MobileBy from appium.webdriver.common.touch_action import TouchAction from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By desired_caps = { "platformName": "Android", "platformVersion": "10", "deviceName": "your_device_name", "appPackage": "com.example.app", "appActivity": "com.example.app.MainActivity" } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 等待直到应用启动完成 WebDriverWait(driver, 30).until(EC.presence_of_element_located((MobileBy.ID, "com.example.app:id/button_login"))) # 获取应用权限许可 driver.start_activity("com.android.settings", ".Settings") driver.find_element(By.ID, "com.android.settings:id/search").click() driver.find_element(By.ID, "com.android.settings:id/search_src_text").send_keys("app permissions") driver.find_element(By.XPATH, "//androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]").click() driver.find_element(By.XPATH, "//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]/android.widget.Switch").click() driver.press_keycode(4) driver.press_keycode(4) # 返回应用 driver.start_activity("com.example.app", "com.example.app.MainActivity") ``` 在上面的代码中,首先定义了一个 `desired_caps` 字典,其中包含了连接的设备信息和应用信息。然后使用该字典创建了一个 `webdriver` 对象。在等待应用启动完成后,使用 `start_activity` 方法打开系统设置应用,模拟用户点击进入应用权限页面,打开第一个权限开关,最后返回到测试应用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值