自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(41)
  • 收藏
  • 关注

原创 调用np.var函数时出现inf值的解决方法

调用np.var函数时出现inf值的解决方法

2022-11-18 15:02:41 477 1

原创 Pycharm快捷键Ctrl+Alt+V无法使用

解决自己的Pycharm快捷键Ctrl+Alt+V无法使用的问题

2022-10-26 21:11:14 380

原创 Python编程 从入门到实践 练习11-3

11-3 雇员employee.py# 雇员# 编写一个名为Employee的类,其方法__init__()接受名、姓和年薪,并将他们都存储到属性中。class Employee(): def __init__(self, first_name, last_name, annul_salary): self.first_name = first_name self.last_name = last_name self.annul_salary = annul_salary #

2021-04-19 10:40:29 731

原创 Python编程 从入门到实践 练习11-1、练习11-2

11-1 城市和国家city_functions.py# 城市和国家def get_city_country(city, country): """返回格式为City, Country的字符串""" city_country = city + ', ' + country return city_country.title()test_cities.pyimport unittestfrom city_functions import get_city_countryclass Ci

2021-04-16 11:19:08 451

原创 Python编程 从入门到实践 练习10-11~练习10-13

10-11 喜欢的数字store_love_number.py# 喜欢的数字import jsonlove_number = input("Please enter your favorite number: ")filename = 'lovenumber.json'with open (filename, 'w') as f_obj: json.dump(love_number, f_obj)love_number.pyimport jsonfilename = 'lov

2021-02-21 11:28:46 366

原创 Python编程 从入门到实践 练习10-6~练习10-10

10-6 加法运算(与10-7程序相同)10-7 加法计算器print("Please enter two number.Or enter 'q' to quit.\n")while True: num1 = input("first number: ") if num1 == 'q': break num2 = input("second number: ") if num1 == 'q': break try: add = int(num1) + int(num2) ex

2021-01-23 23:00:32 484

原创 Python编程 从入门到实践 练习10-3~练习10-5

10-3 访客filename = 'guest.txt'name = input("Please enter your name: ")with open(filename, 'w') as file_object: file_object.write(name)10-4 访客名单filename = 'guest_book.txt'with open(filename, 'a') as file_object: name = input("Please enter your n

2021-01-19 17:20:44 350

原创 Python编程 从入门到实践 练习10-1、练习10-2

10-1 Python学习笔记filename = 'learning_python.txt'# 第一次打印读取整个文件with open(filename) as file_object: contents = file_object.read() print(contents)# 第二次打印时遍历文件对象with open(filename) as file_object: for line in file_object: print(line.rstrip())# 第三次打

2021-01-18 10:32:30 379

原创 Python编程 从入门到实践 练习9-13、练习9-14

9-13 使用OrderedDict# 打印编程词汇的含义# 再添加5个python术语from collections import OrderedDictpython_lists = OrderedDict()python_lists['append'] = '将元素添加到列表末尾'python_lists['insert'] = '可在列表的任何位置添加新元素'python_lists['pop'] = '删除列表末尾的元素' # 用循环遍历字典for word, mean

2021-01-14 10:59:33 860

原创 Python编程 从入门到实践 练习9-10~练习9-12

导入Restaurant类from restaurant import Restaurant# 创建一个实例my_restaurant = Restaurant('Go Believe', 'steamed stuffed bun')# 打印多少人就餐过print(my_restaurant.number_served)9-11 导入Admin类from user import User, Privileges, Adminfirst_admin = Admin('Ac', 'Fun

2021-01-13 20:23:36 342

原创 Python编程 从入门到实践 练习9-6~练习9-9

9-6 冰淇淋小店# 创建餐馆类的实例并调用class Restaurant(): """一次模拟餐馆的简单尝试""" # 添加一个名为number_served的属性,并将其默认值设置为0 def __init__(self, restaurant_name, cuisine_type): """初始化属性restaurant_name和cuisine_type""" self.restaurant_name = restaurant_name self.cuisine_type =

2021-01-07 20:44:36 486 1

原创 Python编程 从入门到实践 练习9-4~练习9-5

9-4 就餐人数# 创建餐馆类的实例并调用class Restaurant(): """一次模拟餐馆的简单尝试""" # 添加一个名为number_served的属性,并将其默认值设置为0 def __init__(self, restaurant_name, cuisine_type): """初始化属性restaurant_name和cuisine_type""" self.restaurant_name = restaurant_name self.cuisine_type =

2021-01-06 08:02:34 314

原创 Python编程 从入门到实践 练习9-1~9-3

9-1 餐馆# 创建餐馆类的实例并调用class Restaurant(): """一次模拟餐馆的简单尝试""" def __init__(self, restaurant_name, cuisine_type): """初始化属性restaurant_name和cuisine_type""" self.restaurant_name = restaurant_name self.cuisine_type = cuisine_type def describe_restaur

2021-01-02 11:47:39 473 3

原创 Python编程 从入门到实践 练习8-15~练习8-17

8-15 打印模型printing_functions.py# 打印模型def print_models(unprinted_designs, completed_models): """ 模拟打印每个设计,直到没有未打印的设计为止 打印每个设计后,都将其移到列表completed_models中 """ while unprinted_designs: current_design = unprinted_designs.pop() # 模拟根据设计制作3D打印模型的过程 pr

2020-08-26 16:34:58 783

原创 Python编程 从入门到实践 练习8-12~练习8-14

8-12 三明治# 三明治def sandwiches(*ingredients): """概述三明治""" print(ingredients)sandwiches('Turkey breast', 'ham', 'American or cheddar cheese', 'chopped or shredded lettuce', 'tomatoes and green peppers')sandwiches('ketchup', 'bacon')sandwiches('bacon'

2020-08-26 11:16:56 684

原创 Python编程 从入门到实践 练习8-9~练习8-11

8-9 魔术师# 魔术师def show_magicians(magicians): """打印列表中每个魔术师的名字""" for magician in magicians: print(magician.title())magicians = ['dynamo', 'jason latimer', 'franz harary']show_magicians(magicians)8-10 了不起的魔术师# 魔术师# 了不起的魔术师def show_magicians(mag

2020-08-26 10:17:43 951

原创 Python编程 从入门到实践 练习8-6~练习8-8

8-6 城市名# 城市名def city_country(city, country): print(city.title() + ", " + country.title())# 使用三个城市-国家对调用这个函数city_country('santiago', 'chile')city_country('beijing', 'china')city_country('shanghai', 'china')8-7 专辑# 专辑def make_album(singer, name,

2020-08-26 08:39:42 844

原创 Python编程 从入门到实践 练习8-3~练习8-5

8-3 T恤# T恤def make_shirt(size, message): """概要的说明T恤的尺码和字样""" print("\nT-shirt size is " + size + ".") print("The words on the T-shirt are " + message + ".")# 使用位置实参调用函数制作一件T恤make_shirt('XL', 'good morning')# 使用关键字实参调用函数make_shirt(message = 'good

2020-08-25 08:40:02 572

原创 Python编程 从入门到实践 练习8-1、练习8-2

8-1 消息# 消息# 打印一个句子,指出在本章学的是什么def display_message(): print("Learn functions in this chapter.")# 调用函数display_message()8-2 喜欢的图书# 喜欢的图书def favorite_book(title): """打印一条消息""" print("One of my favorite books is " + title.title() + ".")# 调用函数,传递一

2020-08-24 10:34:11 295

原创 python编程 从入门到实践 练习7-8~练习7-10

7-8 熟食店三名治的名字可以参考该网站:list of sandwiches# 熟食店sandwich_orders = ['bacon', 'barbecue', 'bauru', 'tuna']finished_sandwiches = []while sandwich_orders: sandwich = sandwich_orders.pop() print("I made your " + sandwich + " sandwich.") finished_sandwich

2020-08-23 09:21:56 515

原创 python编程 从入门到实践 练习7-4~7-7

7-4 比萨配料# 比萨配料active = Trueprompt = "\nPlease enter a pizza ingredient: "while active: message = input(prompt) if message == 'quit': active = False else: print("We will add " + message + " in pizza.")7-5 电影票# 电影票prompt = "How old are you? "

2020-08-21 18:19:23 879

原创 Python编程 从入门到实践 练习7-1~7-3

7-1 汽车租赁# 汽车租赁car = input("What kind of car do you want to rent? ")print("Let me see if I can find you a " + car.title())7-2 餐馆订位# 餐馆订位people = int(input("How many people will come to eat? "))if people > 8: print("There are no empty tables.")

2020-08-19 17:01:08 366

原创 3.1自己的手写数字

import scipy.miscimg_array = scipy.misc.imread(image_file_name, flatten = True)img_data = 255.0 - img_array.reshape(784)img_data = (img_data / 255.0 * 0.99) + 0.01使用书上的这段代码会报错查看scipy的官网,我发现该函数已经被弃用:The following functions in scipy.misc are deprecate

2020-08-15 16:30:41 195

原创 Python编程 从入门到实践 练习6-7~练习6-12

6-7 人# 使用字典存储熟人的信息person1 = { 'first_name': 'william', 'last_name': 'cliton', 'age': 20, 'city': 'new york', }# 再创建两个表示人的字典person2 = { 'first_name': 'leonhard', 'last_name': 'euler', 'age': 16, 'city': 'basel', }person3 = { 'first_name': 'c

2020-08-10 18:25:02 694

原创 Python编程 从入门到实践 练习6-4~练习6-6

6-4 词汇表2# 打印编程词汇的含义# 再添加5个python术语python_lists = { 'append': '将元素添加到列表末尾', 'insert': '可在列表的任何位置添加新元素', 'pop': '删除列表末尾的元素', 'remove': '根据值删除元素', 'sort': '对列表进行永久性排序', 'set':'类似于列表,但每个元素都必须是独一无二的', 'values':'返回一个值列表,而不包含任何键', 'keys':'访问字典的键', 'de

2020-07-26 09:36:31 766

原创 Python编程 从入门到实践 练习6-1~练习6-3

6-1 人# 使用字典存储熟人的信息person = { 'first_name': 'william', 'last_name': 'cliton', 'age': 20, 'city': 'new york', }print(person)6-2 喜欢的数字# 使用一个字典来存储一些人喜欢的数字love_numbers = { 'ford': 4, 'david': 6, 'louis': 7, 'sam':1, 'bob':7, }print(love_numb

2020-07-15 15:52:45 916

原创 Python编程 从入门到实践 练习5-8~5-11

5-8 以特殊方式跟管理员打招呼# 以特殊方式跟管理员打招呼users = ['admin', 'alice', 'bob', 'carlos', 'david']for user in users: if user == 'admin': print("Hello admin, would you like to see a status report?") else: print("Hello " + user + ", thank you for logging in again.

2020-07-09 16:33:27 899

原创 Python编程 从入门到实践 练习5-3~5-7

5-3 外星人颜色#1# 外星人颜色版本1,通过测试alien_color = 'green'# 编写一条if语句,检查外星人是否是绿色的if alien_color == 'green': print("You got 5 points.")# 外星人颜色版本2,未通过测试alien_color = 'yellow'# 编写一条if语句,检查外星人是否是绿色的if alien_color == 'green': print("You got 5 points.")5-4 外星

2020-07-08 12:20:52 912

原创 Python编程 从入门到实践 练习5-1、5-2

5-1 条件测试car = 'subaru'print("Is car == 'subaru'? I predict True.")print(car == 'subaru')print("\nIs car == 'audi'? I predict False.")print(car == 'audi')print("\nIs car != 'subaru'? I predict False.")print(car != 'subaru')print("\nIs car != 'aud

2020-07-05 10:49:21 686 2

原创 Python编程 从入门到实践 练习4-13

4-13 自助餐使用一个for循环将该餐馆提供的五种食品都打印出来#五种简单的食品foods = ('sandwich', 'rice', 'dumpling', 'noodle', 'pizza')for food in foods: print(food)尝试修改其中的一个元素,核实Python确实会拒绝你这样做。#五种简单的食品foods = ('sandwich', 'rice', 'dumpling', 'noodle', 'pizza')#尝试修改元组中的一个元素

2020-06-28 09:59:17 637

原创 Python编程 从入门到实践 练习4-10~4-12

4-10 切片cubes = []for value in range(1,11): cubes.append(value**3)print(cubes)print("The first three items in the list are:")#切片不包括最后的索引值所指print(cubes[0:3])print("The items from the middle of the list are:")print(cubes[4:7])print("The last three i

2020-06-26 11:06:09 560

原创 Python编程 从入门到实践练习4-3~4-9

数到20for number in range(1,21): print(number)4-4 一百万numbers = list(range(1,1000001))for number in numbers: print(number)中间用Ctrl + C停止输出。不打断输出的最后结果:4-5 计算1~1 000 000的总和numbers = list(range(1,1000001))print(min(numbers))print(max(numbers))pr

2020-06-19 16:47:58 338

原创 Python编程 从入门到实践 练习4-1、4-2

4-1 比萨pizzas = ['seafood pizza', 'sausage pizza', 'cheese pizza']for pizza in pizzas: print(pizza.title()) print('I like ' + pizza + '.\n')print('I really love pizza!')4-2 动物animals = ['fish', 'cat', 'dog']for animal in animals: print(animal.tit

2020-06-18 19:42:15 367

原创 Python编程 从入门到实践 练习3-11

3-11 有意引发错误#建一个列表,使用一次本章的每个函数来处理这个列表cities = ['zurich', 'berlin', 'frankfurt']#len()函数print(len(cities))#sorted()函数print(sorted(cities))print(sorted(cities, reverse = True))#尝试引发索引错误print(cities[3])修改索引后:#建一个列表,使用一次本章的每个函数来处理这个列表cities = ['zu

2020-06-15 09:15:35 298

原创 Pythong编程 从入门到实践 练习3-8~3-10

3-8 放眼世界#存储一些地名并进行一些操作places = ['pyramids', 'great barrier reef', 'niagara falls', 'louvre', 'venice']#按原始顺序打印该列表print(places)#使用sorted()按字母顺序打印这个列表print(sorted(places))#再次打印列表,核实排列顺序未变print(places)#使用sorted()按与字母顺序相反的顺序打印这个列表print(sorted(places,

2020-06-14 15:39:19 324

原创 Python编程 从入门到实践 练习3-4~3-7

3-4 嘉宾名单guest_list = ['alice', 'bob', 'carmen', ]print(guest_list[0].title() + ',please come and have dinner with me.')print(guest_list[1].title() + ',please come and have dinner with me.')print(guest_list[2].title() + ',please come and have dinner wit

2020-06-14 06:46:24 648

原创 Python编程 从入门到实践 第18章Django入门 Windows10操作系统下的实践

18.1.2 建立虚拟环境建立一个新的文件夹,名字是learning_log打开菜单栏输出command注意需要切换到刚刚新建的learning_log。简单介绍一下可能会用到的几种操作:1.在命令提示符输入D:切换到D盘(其它盘以此类推)2.保存在桌面的输入 cd desktop则切换到桌面3.使用cd name1\name2进入其他文件夹(返回上一级用cd …)直接输入python -m venv ll_env18.1.4 激活虚拟环境输入ll_env\Scripts\act

2020-06-12 22:54:57 1249 8

原创 Python编程 从入门到实践 练习3-1~3-3

3-1 姓名#将朋友的姓名存储在列表中,并依次访问打印。names = ['Alice', 'Bob', 'Carmen']print(names[0])print(names[1])print(names[2])3-2 问候语#为每人打印一条消息包含相同的问候语names = ['alice', 'bob', 'carmen']print(names[0].title() + ",how are you?")print(names[1].title() + ",how are yo

2020-06-12 11:37:30 302

原创 Python编程 从入门到实践 练习2-10

2-10 添加注释# 输出最喜欢的数字love_number = 3message = "My favorite number is " + str(love_number)print(message)错误原因:Python中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。参考网址:Python中文编码更改后:# coding=utf-8('='号两边不要加' ',该行前不要有中文,否则会报错)# 输出最喜欢的数字love_number

2020-06-09 15:19:51 656

原创 Python编程 从入门到实践 练习2-8、2-9

2-8 数字8print(5+3)print(9-1)print(2*4)print(16/2)2-9 最喜欢的数字love_number = 3message = "My favorite number is " + str(love_number)print(message)

2020-06-09 12:07:34 297

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除