1. Basic Usage - HomerHaddock/Input-API GitHub Wiki
All example snippets of the package will contain this way to import:
import inputapi as inp
This is just basic examples, more detailed usage will be in other Wiki pages.
Boolean Input
This is for the standard Yes/No type input. You will get True
if Yes, False
if No.
Here is how to get boolean input:
import inputapi as inp
inp.yesNo("Can you see this?")
And you will get this as output.
Can you see this?
Numeric response allowed (y=1, n=2)
[y/n]:
Numeric Input
The Input API supports numerical inputs, both integer and floating point (decimal)
For integers you can use
import inputapt as inp
inp.newLineInt("Age:")
Age:
>
And for floating point
import inputapi as inp
inp.newLineFloat("Distance (meters):")
Distance (meters):
>
String Input
This is the closest to input()
being that it returns what the input()
function gives.
import inputapi as inp
inp.newLineStr("Name:")
Name:
>
Menus
A simple menu is available for things like main menus and similar.
This type of input is part of the more complex part of the Input API.
import inputapi as inp
inp.menu("Option 1", "Option 2", "Option 3", title="Menu")
---Menu---
1: Option 1
2: Option 2
3: Option 3
To select an option input the number assigned to it:
>
Math Based Input
The Input API has only one math based input called RDC
(Radius, Diameter, Circumference)
It will take the radius, diameter, or circumference of a circle and return the radius.
import inputapi as inp
# RDC needs a number as argument
value = inp.newLineFloat("RDC:")
inp.RDC(value)
RDC:
>
---RDC---
1: Radius
2: Diameter
3: Circumference
To select an option input the number assigned to it:
>
Other Functions
There are two other functions that can be used.
import inputapi as inp
# This will pause Python until ENTER is pressed
inp.pause()
# This will clear the terminal
inp.clearScreen()
Press ENTER to continue:
*Terminal clears*