当前位置:网站首页>Trust guessing numbers game
Trust guessing numbers game
2022-07-23 17:47: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 :
边栏推荐
- Differences between nvisual generic cabling management software and network management software
- 你真的了解Redis的持久化机制吗?
- 【Js】检查Date对象是否为Invalid Date
- 不掌握这些坑,你敢用BigDecimal吗?
- True title of Blue Bridge Cup: Card [easy to understand]
- Geometric parametric reconstruction
- LeetCode_455_分发饼干
- 面试官:MySQL 数据库查询慢,除了索引问题还可能是什么原因?
- WARNING: Your password has expired.Password change required but no TTY available.
- Typescript empty array
猜你喜欢

Console calculator developed based on C language

"Now, the number of codes has expanded to astronomical level"

基于OpenPGP的文件管理系统

Unity production QR code scanning

Food safety | ham sausage lunch meat, is it really so unbearable?

Food safety chocolate is also true or false? How much do you know about it

Pymoo learning (3): use multi-objective optimization to find the set of optimal solutions

基于策略路由部署的网络多出口设计研究与实现
![[introduction series of redis] redis builds master-slave servers](/img/94/505ec8eeb9a10e09a00f61565cbaba.png)
[introduction series of redis] redis builds master-slave servers

leetcode刷题:动态规划04(不同路径)
随机推荐
vim 笔记
Three things programmers want to do most | comics
Food safety | drinking fresh milk may infect tuberculosis? Take you to know what is milk sterilization
Kubernetes focuses on kubelet's responsibilities
xlinx pcie xvc
Typescript empty array
Thread pool, who am I? Where am I?
True title of Blue Bridge Cup: Card [easy to understand]
Single cell thesis record (part19) -- a comprehensive comparison on cell type composition information for St data
基于策略路由部署的网络多出口设计研究与实现
In depth understanding of USB communication protocol
[introduction series of redis] data types and related commands of redis
leetcode刷题:动态规划04(不同路径)
Mysql操作
基于C语言开发的控制台计算器
Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
Use Preparedstatement to select and display recorded JDBC programs
isEmpty 和 isBlank 的用法区别,至少一半的人答不上来...
【Js】检查Date对象是否为Invalid Date
Food safety | ham sausage lunch meat, is it really so unbearable?