mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Updated src/Ch02_Programming_a_Guessing_Game.md'.
This commit is contained in:
@@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
use std::io;
|
||||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
println! ("猜猜这个数!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||
|
||||
println! ("秘密数字是:{secret_number}");
|
||||
|
||||
println! ("请输入你的猜数。");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("读取行失败");
|
||||
.expect("读取行失败!");
|
||||
|
||||
println! ("你猜的是: {guess}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user