Skip to content
upizpp edited this page Jan 13, 2024 · 2 revisions

Input Syntax

Similar to io.print(), you must import the io module first. There are only two ways to input values in PhiScript.

Usage of io.input()

import io;
var x = io.input(<prompt>);

Example of io.input()

import io;
var x = io.input("Whats your name?");
io.print(x);

Usage of io.get_number()

import io;
var x = io.get_number(<prompt>, <output after input a invalid number>);

io.get_number() is similar to this Python code:

def get_number(input_tip, bad_value, white_list):
    while(True):
        try:
            s = input(input_tip)
            if s in white_list:
                break
            x = int(s)
            break
        except ValueError:
            print(bad_value)

Example of io.get_number()

import io;
var x = io.input("How old are you:", "Invalid input:");
io.print(x);
Clone this wiki locally