PYTHON
Lesson controls with
6 input/output
functi0n
Input/Output Functions
Input may come from the user directly through the
keyboard or from external sources like files or
databases.
While output can be displayed directly to the
console or IDE, to the screen through a Graphical
User Interface (GUI), or again to an external
source.
input/output function
Let’s create a input/output function using the int()
To show the output we use:
entry.get() retrieves the value from an entry widget (text input field).
int(value) attempts to convert the retrieved value to an integer.
If the conversion succeeds, a message box displays the integer
value as "Age: {integer_value}".
If the conversion fails (e.g., if the user entered non-numeric
characters), a ValueError is raised, and the code inside the except
block is executed.
In the except block, messagebox.showerror() displays an error
message box with the title "Error" and the message "Invalid input!".
input/output function
To input our information we used a simple textbox
and button.
Also use command and add the name of function
which is show_int .
input/output function
•Here is an example of the code
input/output function
When this code is executed, it produce this result
input/output function
When we input a number with decimal, it produce this
result
input/output function
Let’s create a input/output function using the string()
To show the output we use:
entry.get() retrieves the value from an entry widget (text input field).
If the conversion succeeds, a message box displays the integer
value as “Name: {integer_value}".
input/output function
To input our information we used a simple textbox
and button.
Also use command and add the name of function
which is show_string.
input/output function
•Here is an example of the code
input/output function
When this code is executed, it produce this result
input/output function
Let’s create a input/output function using the
double()
To show the output we use:
entry.get() retrieves the value from an entry widget (text input field).
float(value) attempts to convert the retrieved value to an float.
If the conversion succeeds, a message box displays the integer
value as “GWA: {integer_value}".
If the conversion fails (e.g., if the user entered non-numeric
characters), a ValueError is raised, and the code inside the except
block is executed.
In the except block, messagebox.showerror() displays an error
message box with the title "Error" and the message "Invalid input!".
input/output function
To input our information we used a simple textbox
and button.
Also use command and add the name of function
which is show_double
input/output function
•Here is an example of the code
input/output function
When this code is executed, it produce this result
input/output function
When we input a letter, it produce this result