当前位置:网站首页>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 :
边栏推荐
- CockroachDB: The Resilient Geo-Distributed SQL Database 论文阅读笔记
- 数据治理:数据治理框架(第一篇)
- Ssgssrcsr differences
- 基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)
- 小程序常用组件小结
- HDU - 1069 Monkey and Banana(DP+LIS)
- QDataStream的簡單讀寫驗證
- Lock free concurrency of JUC (leguan lock)
- LevelDB源码分析之LRU Cache
- Actual combat: gateway api-2022.2.13
猜你喜欢

What is the at instruction set often used in the development of IOT devices?

Causes of short circuit of conductive slip ring and Countermeasures

And search: the suspects (find the number of people related to the nth person)

Leetcode top 100 questions 1 Sum of two numbers

Set set detailed explanation

Simple implementation of database connection pool

基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)

Data consistency between redis and database

LRU cache for leveldb source code analysis

Practice of combining rook CEPH and rainbow, a cloud native storage solution
随机推荐
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
QDataStream的簡單讀寫驗證
Web Security (x) what is OAuth 2.0?
RecycleView的一些使用
Unity 使用Sqlite
boot+jsp的高校社团管理系统(附源码下载链接)
Rainbond结合NeuVector实践容器安全管理
Use and principle of Park unpark
Actual combat: gateway api-2022.2.13
Spanner 论文小结
Vérification simple de la lecture et de l'écriture de qdatastream
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
0xc000007b应用程序无法正常启动解决方案(亲测有效)
tese_Time_2h
Mongodb学习篇:安装后的入门第一课
Memtable for leveldb source code analysis
Unity project experience summary
从底层结构开始学习FPGA----RAM IP的定制与测试