python自动化办公选择题_python自动化开发-[第一天]-练习题
1、使用while循環輸入 1 2 3 4 5 6 8 9 10
i = 1
while i < 11:
if i == 7:
i += 1
continue
print (i)
i += 1
2、求1-100的所有數的和
#第一種方法
value =0for i in range(1,101):
value= value +iprint(value)#第二種方法
value =0
i= 1
while i < 101:
value+=i
i+=1
print (value)
3、輸出 1-100 內的所有奇數
1 #第一種方法
2 for i in range(1,101):3 if i%2 == 1:4 print(i)5
6 #第二種方法
7 i=1
8 while i < 101:9 if i%2 == 1:10 print(i)11 i+=1
4、輸出 1-100 內的所有偶數
#第一種方法
for i in range(1,101):if i%2 ==0:print(i)#第二種方法
i=1
while i < 101:if i%2 ==0:print(i)
i+=1
5、求1-2+3-4+5 ... 99的所有數的和
value =0for i in range(1,100):if i%2 == 1:
value+=ielse:
value-=iprint (value) #print要放在和for循環同一級目錄
6、 元素分類
有如下值集合 v1 = [11,22,33,44,55,66,77,88,99,90],
將所有大于 66 的值保存至字典的第一個key中,將小于 66 的值保存至第二個key的值中。
即: {'k1': 大于66的所有值, 'k2': 小于66的所有值}
print ('\033[1;35m Welcome to my shop ! \033[0m')for item ingoods:
i+=1
print ('\033[1;35m %d.商品%s-->價格%s \033[0m' %(i,item['name'],item['price']))print ('\033[1;35m 5.查詢資產余額 \033[0m')print ('\033[1;35m 6.退出 \033[0m')print ('\033[1;35m 7.充值 \033[0m')whileTrue:
user_input= int(input('請輸入所選商品 :').strip())if user_input == 6:print('歡迎下次光臨 !')break
elif user_input == 5:print('當前資產剩余: %s' %(money))elif user_input == 7:
input_money= int(input('請輸入充值金額 :'))
money+=input_moneyelif user_input !=5 and user_input !=6 and user_input !=7:
user_input= user_input - 1
if money < int(goods[user_input]['price']):print ('您余額不足,無法購買商品')else:
money= money - goods[user_input]['price']
name= goods[user_input]['name']print ('消費成功,您已購買:%s,當前余額:%s' %(name,money))
8、用戶交互,顯示省市縣三級聯動的選擇
dic = {
"河北": {
"石家莊": ["鹿泉", "藁城", "元氏"],
"邯鄲": ["永年", "涉縣", "磁縣"],
}
"河南": {
...
}
"山西": {
...
}
}
city_list =[]whileTrue:
user_input= input('請輸入省份:')if user_input indic.keys():for center indic[user_input]:
city_list.append(center)print(city_list)
user_input_center= input('請輸入省徽:')if user_input_center indic[user_input].keys():print(dic[user_input][user_input_center])
user_input_region= input('請輸入區縣:')if user_input_region indic[user_input][user_input_center]:print ('%s省徽是%s,區縣是%s' %(user_input,user_input_center,user_input_region))break
else:print ('輸入區縣有誤,請重新輸入')else:print ('輸入省徽有誤,請重新輸入')else:print ('輸入省份有誤,請重新輸入..')
總結
以上是生活随笔為你收集整理的python自动化办公选择题_python自动化开发-[第一天]-练习题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 消息称游戏《血缘诅咒》改编电影正筹划拍摄
- 下一篇: 科技昨夜今晨 1106:中国移动 5G