The document discusses input/output functions in Python, explaining how to retrieve user input from text fields and convert it into different data types such as integers, strings, and floats. It provides examples of how to handle successful conversions and errors using message boxes. The document also outlines the use of GUI elements like textboxes and buttons to facilitate user interaction.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views16 pages
Python_3_Controls with InputOutput Function
The document discusses input/output functions in Python, explaining how to retrieve user input from text fields and convert it into different data types such as integers, strings, and floats. It provides examples of how to handle successful conversions and errors using message boxes. The document also outlines the use of GUI elements like textboxes and buttons to facilitate user interaction.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16
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
VTU Exam Question Paper With Solution of BPLCK105B Introduction To Python Programming May-2023-Dr.M.Farida Begam Tamal Sarkar, DR - Vakula Rani, Vijay Anand, Shyamali Das