[PYTHON] Even or odd

A program that determines whether it is even or odd

A new program that determines whether it is an even number or an odd number, which often appears in the early stages of language acquisition.

program

python

pythonevenoroddjudge.py


def is_even(num):
    return num % 2 == 0


num = float(input())

print(is_even(num))

julia

juliaevenoroddjudge.jl


function is_even(num)
    return num % 2 == 0
end
function asknumber()
    print("Enter a number: ")
    parse(Float64, readline())
end
num = asknumber()
is_even(num)

The julia code uses a function, but you can also write an if statement. In another article about that.

rust

use std::io;
use std::io::Write;
use std::io::stdout;
 
fn main() {
 
    println!("input number : ");
        stdout().flush().unwrap();
 
    let mut number = String::new();
 
    io::stdin().read_line(&mut number)
        .expect("failured!");
 
    let number: u32 = number.trim().parse()
        .expect("input number");
 
    if number % 2 == 0 {
        println!("{} is even",number);
    } else {
        println!("{} is odd",number);
    }
}

I will write other languages later.

Recommended Posts

Even or odd
[Pandas speedup] Flag odd or even lines
Blender 2.9, Python Odd Even Building
Programmer 8th grade [Even or Odd (even or odd)] Can you solve this programming problem? !!