update numbers.md

This commit is contained in:
sunface 2022-02-28 17:27:33 +08:00
parent 57ae037fae
commit 9b644dda0e
3 changed files with 39 additions and 21 deletions

1
en/book Submodule

@ -0,0 +1 @@
Subproject commit 036e93c39b5b15957364207bfdfaf93e0b06ffc8

View File

@ -2,11 +2,13 @@
### Integer
🌟 remove something to make it work
🌟
> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us
```rust,editable
// remove something to make it work
fn main() {
let x: i32 = 5;
let mut y: u32 = 5;
@ -17,20 +19,22 @@ fn main() {
}
```
🌟 fill the blank
🌟
```rust,editable
// fill the blank
fn main() {
let v: u16 = 38_u8 as __;
}
```
🌟🌟🌟 modify `assert_eq!` to make it work
🌟🌟🌟
> Tips: If we don't explicitly give one type to a varible, then the compiler will infer one for us
```rust,editable
// modify `assert_eq!` to make it work
fn main() {
let x = 5;
assert_eq!("u32".to_string(), type_of(&x));
@ -42,18 +46,20 @@ fn type_of<T>(_: &T) -> String {
}
```
🌟🌟 fill the blanks to make it work
🌟🌟
```rust,editable
// fill the blanks to make it work
fn main() {
assert_eq!(i8::MAX, __);
assert_eq!(u8::MAX, __);
}
```
🌟🌟 fix errors and panics to make it work
🌟🌟
```rust,editable
// fix errors and panics to make it work
fn main() {
let v1 = 251_u8 + 8;
let v2 = i8::checked_add(251, 8).unwrap();
@ -61,9 +67,10 @@ fn main() {
}
```
🌟🌟🌟 modify `assert!` to make it work
🌟🌟🌟
```rust,editable
// modify `assert!` to make it work
fn main() {
let v = 1_024 + 0xff + 0o77 + 0b1111_1111;
assert!(v == 1579);
@ -72,10 +79,11 @@ fn main() {
### Floating-Point
🌟 replace ? with your answer
🌟
```rust,editable
// replace ? with your answer
fn main() {
let x = 1_000.000_1; // ?
let y: f32 = 0.12; // f32
@ -112,9 +120,10 @@ fn main() {
}
```
🌟🌟 fill the blanks
🌟🌟
```rust,editable
// fill the blanks
use std::ops::{Range, RangeInclusive};
fn main() {
assert_eq!((1..__), Range{ start: 1, end: 5 });
@ -124,10 +133,10 @@ fn main() {
### Computations
🌟 fill the blanks
🌟
```rust,editable
// fill the blanks
fn main() {
// Integer addition
assert!(1u32 + 2 == __);

View File

@ -2,12 +2,13 @@
### 整数
🌟 移除某个部分让代码工作
🌟
> Tips: 如果我们没有显式的给予变量一个类型,那编译器会自动帮我们推导一个类型
```rust,editable
// 移除某个部分让代码工作
fn main() {
let x: i32 = 5;
let mut y: u32 = 5;
@ -18,20 +19,22 @@ fn main() {
}
```
🌟 填空
🌟
```rust,editable
// 填空
fn main() {
let v: u16 = 38_u8 as __;
}
```
🌟🌟🌟 修改 `assert_eq!` 让代码工作
🌟🌟🌟
> Tips: 如果我们没有显式的给予变量一个类型,那编译器会自动帮我们推导一个类型
```rust,editable
// 修改 `assert_eq!` 让代码工作
fn main() {
let x = 5;
assert_eq!("u32".to_string(), type_of(&x));
@ -43,18 +46,20 @@ fn type_of<T>(_: &T) -> String {
}
```
🌟🌟 填空,让代码工作
🌟🌟
```rust,editable
// 填空,让代码工作
fn main() {
assert_eq!(i8::MAX, __);
assert_eq!(u8::MAX, __);
}
```
🌟🌟 解决代码中的错误和 `panic`
🌟🌟
```rust,editable
// 解决代码中的错误和 `panic`
fn main() {
let v1 = 251_u8 + 8;
let v2 = i8::checked_add(251, 8).unwrap();
@ -62,9 +67,10 @@ fn main() {
}
```
🌟🌟🌟 修改 `assert!` 让代码工作
🌟🌟🌟
```rust,editable
// 修改 `assert!` 让代码工作
fn main() {
let v = 1_024 + 0xff + 0o77 + 0b1111_1111;
assert!(v == 1579);
@ -73,10 +79,11 @@ fn main() {
### 浮点数
🌟 将 ? 替换成你的答案
🌟
```rust,editable
// 将 ? 替换成你的答案
fn main() {
let x = 1_000.000_1; // ?
let y: f32 = 0.12; // f32
@ -85,7 +92,7 @@ fn main() {
```
🌟🌟🌟 使用两种方法来让下面代码工作
> Tips: 1. abs 2. f32
> 提示: 1. abs 2. f32
```rust,editable
@ -113,9 +120,10 @@ fn main() {
}
```
🌟🌟 填空
🌟🌟
```rust,editable
// 填空
use std::ops::{Range, RangeInclusive};
fn main() {
assert_eq!((1..__), Range{ start: 1, end: 5 });
@ -125,10 +133,10 @@ fn main() {
### 计算
🌟 填空
🌟
```rust,editable
// 填空
fn main() {
// 整数加法
assert!(1u32 + 2 == __);