三级python 等级考试_Python代码之三级登录

# -*- coding:utf-8 -*-

#Author:Mr Gan

china_map ={

"华南区":

{

"广东省":{"广州市":["越秀区","天河区"],"东莞市":["哥台区","沧桑区"]},

"海南省":{"海口市":["龙河区","丰台区"],"三亚市":["苍山区","晋安区"]}

},

"华北区":

{

"河北省":{"石家庄市":['台州区','河内区'],"唐山市":['台南区','雄安区']}

}}

while True:

for i in china_map:#遍历第一级key

print(i)

choice_1 = input("选择进入》》:")

if choice_1 in china_map:

while True:

for i2 in china_map[choice_1]:#遍历第二级key

print("\t\t",i2)

choice_2 = input("选择进入》》:")

if choice_2 == "q":

break

if choice_2 in china_map[choice_1]:

while True:

for i3 in china_map[choice_1][choice_2]:#遍历第三级key

print("\t\t\t\t", i3)

choice_3 = input("选择进入》》:")

if choice_3 == "q":

break

if choice_3 in china_map[choice_1][choice_2]:

while True:

for i4 in china_map[choice_1][choice_2][choice_3]:

print("\t\t\t\t\t\t",i4)

choice_4 = input("最后一层,按q返回:")

if choice_4 == "q":

break

else:

pass

代码有点low

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资料:青少年编程等级考试 - Python编程三级试卷5 1. 请问Python中如何定义函数?函数的定义格式是怎样的? 在Python中,我们可以使用关键字“def”来定义函数。函数的定义格式如下: def 函数名(参数列表): 函数体 2. Python中如何判断一个数是否为质数? 判断一个数是否为质数可以使用循环判断的方法。我们可以使用for循环从2遍历到该数的平方根,如果能整除,则说明不是质数。 def is_prime(num): if num < 2: return False for i in range(2, int(num**0.5)+1): if num % i == 0: return False return True 3. 请问Python中如何读取文本文件Python中可以使用open函数来打开文件,并且使用readlines方法来读取文本文件的内容。 def read_file(file_name): try: with open(file_name, 'r') as file: lines = file.readlines() for line in lines: print(line.strip()) # 使用strip方法去除换行符 except FileNotFoundError: print("文件未找到!") 4. 如何使用Python进行文件的写入操作? 使用Python进行文件写入操作,可以使用open函数来打开文件,并且使用write方法来进行写入。 def write_file(file_name, content): with open(file_name, 'w') as file: file.write(content) 5. 请问Python中如何使用正则表达式进行匹配? 在Python中,可以使用re模块来进行正则表达式的匹配操作。 import re pattern = r'\d+' # 匹配数字 text = 'Hello123World456' result = re.findall(pattern, text) print(result) # 输出['123', '456'] 以上就是关于资料《青少年编程等级考试 - Python编程三级试卷5》的解答。希望能对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值