当前位置:网站首页>Trust guessing numbers game
Trust guessing numbers game
2022-07-01 05:36:00 【pilaf1990】
Video reference bilibili:https://www.bilibili.com/video/BV1hp4y1k7SV?p=6&vd_source=0299ee6ffe3815178fa7786dd32402d1
Cargo.toml file ( similar java Of maven pom.xml file , For managing dependent versions ) Content :
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"
main.rs File contents of :
use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
println!(" Guess the number game starts ");
// rand = "0.8.5" Version of gen_range To pass low..high or low..=high This way,
// Generate a 1 To 100 The random number
let secret_number = rand::thread_rng().gen_range(1..101);
loop {
println!(" Please guess a number ");
// mut A modifier variable indicates that the value of the variable is variable
let mut guess = String::new();
// Read a number from the console
io::stdin().read_line(&mut guess).expect(" Can't read ");
let guess:u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => {
println!(" It's not a number , Re input ");
continue;
},
};
println!(" Your guess is :{}",guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!(" Your input is too small "),
Ordering::Greater => println!(" Your input is too big "),
Ordering::Equal => {
println!(" You win , Guessed it , The mystery number is :{}",guess);
break;
}
}
}
}
Program running effect :
边栏推荐
- [SRS] use of Vhost isolated stream: push / pull Stream Address
- Wild melon or split melon?
- 2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
- 3D建模與處理軟件簡介 劉利剛 中國科技大學
- Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
- CentOS 7使用yum安装PHP7.0
- And search: the suspects (find the number of people related to the nth person)
- HDU - 1024 Max Sum Plus Plus(DP)
- printk 调试总结
- Rust hello-word
猜你喜欢

Mongodb learning chapter: introduction after installation lesson 1

How to select conductive slip ring material

多表操作-外键级联操作

Practice of combining rook CEPH and rainbow, a cloud native storage solution

LevelDB源码分析之memtable

Leetcode top 100 questions 1 Sum of two numbers

One click deployment of highly available emqx clusters in rainbow

LRU cache for leveldb source code analysis

Causes of short circuit of conductive slip ring and Countermeasures

In depth understanding of condition source code interpretation and analysis of concurrent programming
随机推荐
printk 调试总结
Simple implementation of database connection pool
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
What is the at instruction set often used in the development of IOT devices?
Txncoordsender of cockroachdb distributed transaction source code analysis
Usage and principle of synchronized
智慧运维:基于 BIM 技术的可视化管理系统
Leetcode top 100 questions 1 Sum of two numbers
Variable binding and deconstruction for rudimentary rust
El cascade echo failed; El cascader does not echo
Unity uses SQLite
Speed regulation and stroke control based on Ti drv8424 driving stepper motor
工业导电滑环的应用
el-cascader回显失败;el-cascader回显不出来
LRU cache for leveldb source code analysis
Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
Mathematical knowledge: finding the number of divisors
数据治理:数据治理管理(第五篇)
Rust基础入门之变量绑定与解构
Go learning notes (5) basic types and declarations (4)