你好,我是悦创。
独立博客现在(2023)听来像是很古早的产物。独立域名、服务器空间和原创内容组成了独立博客,听起来是很 Geek 的事。独立博客设置了一道技术门栏,进门以后的人都去做技术博客了(误)。
想写一个博客是从之前就有的想法(2018),有了想法之后就有了疑惑:
- 写博客应该写什么?
- 我的文笔不好,写了没人看怎么办?
- 如果我想写的东西别人已经写过了,我还有必要写吗?
- …
抱着这样的疑惑和犹豫迟迟没有开始,直到最近读到 Alexey Guzey 的 Why you should start a Blog Right Now 才恍然大悟,鼓励了我把想法付诸实践。
Answer the following questions on the pages provided. Please be as neat and clear as possible. Give full answers and show your work where asked
- [5 marks] Complete the truth table for the following expression:
(p && q) || (!p && !q)
p | q | !p | !q | (p && q) | (!p && !q) | (p && q)||(!p && !q) |
---|---|---|---|---|---|---|
T | T | F | F | T | F | T |
T | F | F | T | F | F | F |
F | T | T | F | F | F | F |
F | F | T | T | F | T | T |
你好,我是悦创。
我们先来看看今天要学习的内容:
- 列表、集合、元组、字典
- 链表
1. 你真的了解这四个数据类型吗?
- 列表/list
- 元组/tuple
- 字典/dict
- 集合/set
1.1 列表 VS. 元组
-
可变与不可变
-
选择存储策略
a. 存储经纬度用:元组
b. 存储用户访问:列表
0. 目录
- 一个程序搞定成绩的各种处理需求
1. 一个程序搞定成绩的各种处理需求
- 求某年最好成绩
- 求某年的平均成绩
- 求所有年份最好成绩
- 求某门课历年最好成绩
- 自由发挥……
/**
* @ClassName: ScoreMaster
* @Description: TODO
* @Author: AI悦创
* @Date: 2022/10/9 19:24
* @Version: V1.0
* @Blog: https://www.bornforthis.cn
*/
import java.util.Scanner;
public class ScoreMaster {
public static void main(String[] args) {
// 声明六个变量, 分别代表六门科目的成绩
int YuWenIndex = 0;
int ShuXueIndex = 1;
int WaiYuIndex = 2;
int WuLiIndex = 3;
int HuaXueIndex = 4;
int ShengWuIndex = 5;
int totalScoreCount = 6;
// 每门课的名字
String[] names = new String[totalScoreCount];
names[YuWenIndex] = "语文";
names[ShuXueIndex] = "数学";
names[WaiYuIndex] = "外语";
names[WuLiIndex] = "物理";
names[HuaXueIndex] = "化学";
names[ShengWuIndex] = "生物";
Scanner scanner = new Scanner(System.in);
System.out.println("请输入共有多少年的成绩:");
int yearCount = scanner.nextInt();
double[][] scores = new double[yearCount][totalScoreCount]; // 看几年的数组
for (int i = 0; i < yearCount; i++) {
for (int j = 0; j < totalScoreCount; j++) {
scores[i][j] = 80 + Math.random() * 20;
System.out.println("第" + (i + 1) + "年" + names[j] + "成绩为:" + scores[i][j]);
}
}
boolean cont = true;
while (cont) {
System.out.println("请选择要进行的操作:");
System.out.println("1: 求某年最好成绩\n" +
"2: 求某年的平均成绩\n" +
"3: 求所有年份最好成绩\n" +
"4: 求某门课历年最好成绩");
int oprtId = scanner.nextInt();
int year = 0; // 在 switch 用一块代码块里,不能声明同一个变量,所以直接写在外面,方便。不然得想不同的变量名。
switch (oprtId) {
// 先编写 case
case 1:
// 让用户输入指定的年份
System.out.println("请输入要计算第几年的最好成绩");
year = scanner.nextInt();
if (year <= 0 || yearCount < year) {
System.out.println("非法的年份:" + year);
cont = false;
break;
}
year = year - 1;
// 指定年份的最好成绩的编号,开始假设是0
int bestOfYearScoreId = 0;
// 循环指定年份的成绩,找出最好的成绩
// TODO:如果有两门课的成绩一样,而且都是最高的,怎么办?
for (int i = 1; i < totalScoreCount; i++) {
if (scores[year][bestOfYearScoreId] < scores[year][i]) {
bestOfYearScoreId = i;
}
}
System.out.println("第" + (year + 1) + "年成绩最好的科目为" + names[bestOfYearScoreId] + ",成绩为" + scores[year][bestOfYearScoreId] + "。");
break;
case 2:
System.out.println("请输入要计算第几年的平均成绩");
year = scanner.nextInt();
if (year <= 0 || yearCount < year) {
System.out.println("非法的年份:" + year);
cont = false;
break;
}
year = year - 1;
double totalCountForAvg = 0;
for (int i = 0; i < totalScoreCount; i++) {
totalCountForAvg += scores[year][i];
}
double avgOfYear = totalCountForAvg / totalScoreCount;
System.out.println("第" + (year + 1) + "年的平均成绩为" + avgOfYear + "。");
break;
case 3:
int bestYear = 0;
int bestScore = 0;
for (int i = 0; i < yearCount; i++) {
for (int j = 0; j < totalScoreCount; j++) {
if (scores[bestYear][bestScore] < scores[i][j]) {
bestYear = i;
bestScore = j;
}
}
}
// 视频中代码有错误,应该是使用 bestYear 而不是 year, 鸣谢 @zZGod 帮忙揪出 bug 一只。
System.out.println("所有年度最好成绩为第" + (bestYear + 1) + "年的" + names[bestScore] + ",成绩为" + scores[bestYear][bestScore] + "。");
break;
case 4:
System.out.println("请输入科目编号");
int subjectId = scanner.nextInt();
if (subjectId <= 0 || totalScoreCount < subjectId) {
System.out.println("非法的科目编号:" + subjectId);
cont = false;
break;
}
subjectId = subjectId - 1;
year = 0;
for (int i = 1; i < yearCount; i++) {
if (scores[year][subjectId] < scores[i][subjectId]) {
year = i;
}
}
System.out.println("第" + (year + 1) + "年度" + names[subjectId] + "成绩最好,为" + scores[year][subjectId] + "。");
break;
default:
cont = false;
System.out.println("不支持:" + oprtId + ", 程序结束。");
}
}
}
}
0. 目录
- 如果要存储多年的成绩怎么办?
- 多维数组
- 用多维数组存储多年的成绩
1. 如果要存储多年的成绩怎么办?
- 为每年创建一个数组?
- 这种行为和为每一门成绩创建一个变量很像!
import java.util.Scanner;
public class OneYearOneArray {
public static void main(String[] args) {
// 声明六个变量, 分别代表六门科目的成绩
int YuWenIndex = 0;
int ShuXueIndex = 1;
int WaiYuIndex = 2;
int WuLiIndex = 3;
int HuaXueIndex = 4;
int ShengWuIndex = 5;
// 每门课的名字
String[] names = new String[6];
names[YuWenIndex] = "语文";
names[ShuXueIndex] = "数学";
names[WaiYuIndex] = "外语";
names[WuLiIndex] = "物理";
names[HuaXueIndex] = "化学";
names[ShengWuIndex] = "生物";
// 每门课的成绩
double[] year1 = new double[6];
// 用随机数给成绩赋值
for (int i = 0; i < 6; i++) {
year1[i] = 80 + Math.random() * 20;
}
// 每门课的成绩
double[] year2 = new double[6];
// 用随机数给成绩赋值
for (int i = 0; i < 6; i++) {
year2[i] = 80 + Math.random() * 20;
}
// 每门课的成绩
double[] year3 = new double[6];
// 用随机数给成绩赋值
for (int i = 0; i < 6; i++) {
year3[i] = 80 + Math.random() * 20;
}
double[] yearToUse;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查看第几年的成绩:");
int year = scanner.nextInt();
switch (year) {
case 1:
yearToUse = year1;
break;
case 2:
yearToUse = year2;
break;
case 3:
yearToUse = year3;
break;
default:
System.out.println("输入的年份不对,将查看的是最新一年的成绩");
yearToUse = year3;
break;
}
System.out.println("请输入要查看的成绩编号:");
int scoreIndex = scanner.nextInt();
System.out.println("第" + year + "年的" + names[scoreIndex] + "的成绩是:" + yearToUse[scoreIndex]);
}
}
0. 目录
- 重新认识基本类型的变量
- 认识数组
- 数组的长度
- 数组索引过界会出错
- 让变量代表新的数组
1. 重新认识基本类型的变量
1.1 一个简单的使用变量的程序
import java.util.Scanner;
public class UseVariable {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
System.out.println("创建了变量 a,输入一个整数:");
a = in.nextInt();
System.out.println("给 a 赋值,a 的值为" + a + ",请再次输入一个整数:");
a = in.nextInt();
System.out.println("再次给赋值,现在 a 的值为" + a);
}
}
0. 目录
- 语数外物化生的成绩怎么表示?
- 什么是数组和数组的语法
- 用数组处理 6 门课的成绩
1. 语数外物化生的成绩怎么表示?
- 用六个变量表示,如果有更多的科目怎么办?
- 如果有更多的科目怎么办?
- 如果想求出成绩最高的科目怎么办?
public class SevenScore {
public static void main(String[] args) {
// 声明六个变量, 分别代表六门科目的成绩
int YuWen = 0;
int ShuXue = 0;
int WaiYu = 0;
int WuLi = 0;
int HuaXue = 0;
int ShengWu = 0;
}
}
Midjourney
序号 | 名称 |
---|---|
第一章 Midjourney | |
01 | Midjourney 注册及订阅详细流程 |
Hello, I'm Yue Chuang.
Creating your website with a custom URL is momentous. Your first entrance into fashionable Internet society. A digital debutante ball. A modern promenade. Many of us haven’t staked a claim like this since joining the AIM community behind a clever screen name.
This tutorial will teach you how to publish your website directly from GitHub to a Squarespace domain. GitHub also has a Managing a custom domain for your GitHub Pages site document with helpful instructions.
Given two dictionaries d1
and d2
, create a new dictionary d3
according to the fol-lowing rule (think of transitivity): the entry a:c is in d3
if and only if there is an entry a:b
in d1, and an entry b:c
in d2
.
- [2] Write a function
spell_number(n)
where n is an integer between 1 and 9999. Out-put is that number spelled out in words. So,spell_number(821)
prints eight hundred twenty one, andspell_number(3017)
prints three thousand seventeen.
#Question 1
def spell_number(n):
""" spell a given integer between 1 and 9999
"""
print(spell_number(9307)) # should print nine thousand three hundred seven
print(spell_number(5004)) # should print five thousand four
print(spell_number(1616)) # should print one thousand six hundred sixteen
print(spell_number(13)) # should print thirteen
print(spell_number(906)) # should print nine hundred six
print(spell_number(67)) # should print sixty seven
print(spell_number(632)) # should print six hundred thirty two
print(spell_number(2)) # should print two
print(spell_number(111)) # should print one hundred eleven