Expand description
§Example: guessing game
use simple_std::{prompt, random_int_range};
let number = random_int_range(0..100);
loop {
let input = prompt("guess: ").parse::<i32>().expect("not a number");
if input < number {
println!("Higher");
} else if input > number {
println!("Lower");
} else {
println!("Correct!");
break;
}
}
Functions§
- input
- Reads a single line of input, similar to Pythons
input
function - prompt
- Reads a single line of input, while providing a message that comes on the same line.
- random_
float - Returns a random number from 0 to 1, like Javascript
Math.random
- random_
int_ range - Returns an integer number contained in the range