当前位置:网站首页>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 :
边栏推荐
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
- Rust hello-word
- QDataStream的简单读写验证
- 数据库连接池的简单实现
- Simple implementation of database connection pool
- Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
- Go learning notes (5) basic types and declarations (4)
- el-cascader回显失败;el-cascader回显不出来
- 了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
- One click deployment of highly available emqx clusters in rainbow
猜你喜欢

JDBC常见面试题
![Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation](/img/83/97c0c6e23cbb7b4c2b630c217c5206.jpg)
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation

Simple implementation of database connection pool

Leetcode top 100 questions 1 Sum of two numbers

How to meet the requirements of source code confidentiality and source code security management

Unity project experience summary

How to create a progress bar that changes color according to progress

Leetcode top 100 question 2 Add two numbers

激活函数简述

Typeorm framework
随机推荐
Set set detailed explanation
数据库连接池的简单实现
Is there any good website or software for learning programming? [introduction to programming]?
Flutter 实现每次进来界面都刷新数据
数据治理:数据治理管理(第五篇)
How to create a progress bar that changes color according to progress
Application of industrial conductive slip ring
Ebpf cilium practice (2) - underlying network observability
Redis database deployment and common commands
JDBC common interview questions
Cockroachdb: the resistant geo distributed SQL database paper reading notes
实战:redux的基本使用
Usage and principle of synchronized
担心侵权?必备无版权素材网站分享,不用担心视频剪辑缺素材
Precautions for use of conductive slip ring
3D建模與處理軟件簡介 劉利剛 中國科技大學
Actual combat: basic use of Redux
printk 调试总结
Unity uses SQLite
Unity 使用Sqlite