跳至主要內容
Python exam-2022-online「The University of Melbourne」

Question1

Construct a single Python expression which evaluates to the following values, and incorporates the specified operations in each case (executed in any order).

构造一个 Python 表达式,求值为以下值,并在每种情况下合并指定的操作(以任何顺序执行)。

(a) Output value: 'grin'


AI悦创原创...大约 10 分钟Python 练习Python 练习
Python exam-2019s2「The University of Melbourne」

答案获取须知!

关注公众号:AI悦创,添加我好友。微信:Jiabcdefh

注意:关注公众号,添加好友,备注来意!以此获取答案密码。

公众号:AI悦创【二维码】

The University of Melbourne

School of Computing and Information Systems

Final Examination, Semester 2, 2019

COMP10001 Foundations of Computing


AI悦创原创...大约 6 分钟Python 练习Python 练习
Python exam-2016s1「The University of Melbourne」

欢迎关注我公众号:AI悦创,有更多更好玩的等你发现!

公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQ

方法二:微信:Jiabcdefh


AI悦创原创...小于 1 分钟Python 练习Python 练习
「灰产?」Python生成电话号码并检测有效性

你好,我是悦创。

在之前的内容中,我们分享了办公自动化的 Excel 写入。

那现在这个部分呢,就是为了给你更好的练习,我来带你实现:自动生成电话号码并使用 api 验证电话号码有效性。

# -*- coding: utf-8 -*-
# @Time    : 2022/10/13 19:27
# @Author  : AI悦创
# @FileName: hw01.py
# @Software: PyCharm
# @Blog    :https://bornforthis.cn/
import requests
import random, xlwt


# SET_PHONE = set()


def parse_loop(value):
	template = "{haoduan}{weihao}"
	# weihao = random.randrange(10000000, 99999999)
	weihao = random.randint(11111111, 99999999)
	# print(weihao)
	# global phone_number
	phone_number = template.format(haoduan=value, weihao=weihao)
	# print(key, phone_number)
	return phone_number


def generate_phone():
	phone_dict = {
		"中国联通": ['130', '131', '132', '145', '155', '156', '166', '175', '176', '185', '186', '196'],
		"中国电信": ['133', '149', '153', '180', '181', '189', '173', '177', '190', '191', '193', '199'],
		"中国移动": ['134', '135', '136', '137', '138', '139', '147', '150', '151', '152', '157', '158', '159', '172',
		             '178', '182', '183', '184', '187', '188', '195', '197', '198'],
	}

	key = random.choice(list(phone_dict.keys()))
	value = random.choice(phone_dict[key])
	phone_number = parse_loop(value)
	# return key, phone_number
	return phone_number


# 手机号码归属地查询 Python示例代码
def jude_phone(phone_number: str):
	url = 'https://hcapi02.api.bdymkt.com/mobile'
	params = {}
	params['mobile'] = phone_number

	headers = {
		'Content-Type': 'application/json;charset=UTF-8',
		'X-Bce-Signature': 'AppCode/38c548d4357c487185d818ed4da79a1a'
	}
	r = requests.request("GET", url, params=params, headers=headers)
	# print(r.json())
	return r.json()


def phone_number_exists(json):
	if json["code"] == 200:
		key = json["data"]["types"]
		city = json["data"]["city"]
		city_code = json["data"]["city_code"]
		prov = json["data"]["prov"]
		return [key, city, city_code, prov]
	elif json["code"] == 400:
		return False


def write_excel(content):
	wb = xlwt.Workbook()
	sheet = wb.add_sheet("sheet")
	head_data = ["手机号", "类型", "城市", "城市代号", "省份"]
	for index, head in enumerate(head_data):
		sheet.write(0, index, head)
	for row, detail_list in enumerate(content):
		sheet.write(row+1, 0, detail_list[0])
		sheet.write(row+1, 1, detail_list[1])
		sheet.write(row+1, 2, detail_list[2])
		sheet.write(row+1, 3, detail_list[3])
		sheet.write(row+1, 4, detail_list[4])
	wb.save("phone.xls")



def main():
	r = []
	for _ in range(1000):
		result_lst = []
		phone_number = generate_phone()
		r_json = jude_phone(phone_number)
		result_exists = phone_number_exists(r_json)
		if result_exists:
			result_lst.append(phone_number)
			result_lst.extend(result_exists)
			r.append(result_lst)
			print("result_lst:>>>", result_lst)
		else:
			print("continue...")
			continue
	write_excel(r)


if __name__ == '__main__':
	main()

# print(generate_phone())

AI悦创原创...大约 2 分钟pythonPython 练习pythonPython 练习
Python题目:电影院,函数调用,实现'查看热映电影','订票','查看订单','退票','结账','影评'的功能

你好,我是悦创。

def fun1():
    for i, j in enumerate(re_menu, start=1):
        print('{}、{}\t{}'.format(i, j[0], j[1]))
def fun2():
    while True:
        sel = int(input('请输入选择的电影:'))
        if 1<=sel<=4:
            selected.append(re_menu[sel - 1])
            number = int(input('请问定几张:'))
            count.append(number)
            ctn = int(input('是否继续购票?(0结束,其他数字继续):'))
            if ctn == 0:
                break
        else:
            print('输入错误!')

def fun3():
    print('序号      电影名      票价      张数')
    for i,j in enumerate(selected,start=1):
        print('{}      {}      {}      {}'.format(i,j[0],j[1],count[i-1]))
def fun4():
    while True:
        print('删除前')
        print('序号      电影名      票价      张数')
        for i, j in enumerate(selected, start=1):
            print('{}      {}      {}      {}'.format(i, j[0], j[1], count[i - 1]))
        dlt = int(input('请输入要删除的订单序号:'))
        del selected[dlt - 1]
        del count[dlt - 1]
        print('删除后')
        print('序号      电影名      票价      张数')
        for i, j in enumerate(selected, start=1):
            print('{}      {}      {}      {}'.format(i, j[0], j[1], count[i - 1]))
        re_ctn=int(input('是否继续删除?(0退出/其他数字继续删除):'))
        if re_ctn==0:
            break
def fun5():
    tatle_money=0
    for i,j in enumerate(selected):
        tatle_money+= j[1]*count[i]
    print(tatle_money)
    print('您一共花费:{}元'.format(tatle_money))
def fun6():
    ev=input('请输入您的影评:')
    evaluate.append(ev)
    look=int(input('客官谢谢您的影评!(1查看影评/其他结束)'))
    if look==1:
        print(evaluate)
    else:
        print('欢迎下次再来!您慢走!')
menu=['查看热映电影','订票','查看订单','退票','结账','影评']
re_menu=[['智取威虎山',30],['第一滴血',80],['大圣归来',40],['哪吒',50]]
selected=[]
count=[]
evaluate=[]
while True:
    for i, j in enumerate(menu, start=1):
        print('{}、{}'.format(i, j))
    print('===============================')
    num = int(input('请输入选择功能的编号:'))
    if num == 1:
        fun1()
    elif num == 2:
        fun2()
    elif num == 3:
        fun3()
    elif num == 4:
        fun4()
    elif num==5:
        fun5()
    elif num==6:
        fun6()
    print('===============================')
    all_ctn=int(input('是否继续功能选择(0退出)'))
    if all_ctn==0:
        break

AI悦创原创...大约 2 分钟pythonPython 练习pythonPython 练习