Como hago para limitar el input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Como hago para limitar el input?

Estos haciendo una calculadora si interfaz gráfica en Python y me gustaría hacer un input solo para números y otros solo para algunos signos, hay alguna manera de hacer que solo se puedan colocar números o símbolos para el cálculo? https://code.sololearn.com/cFcNjk23j3qM/?ref=app

8th Oct 2021, 4:58 AM
Gabriel
Gabriel - avatar
28 Answers
+ 4
Como hago para limitar el input? Estos haciendo una calculadora si interfaz gráfica en Python y me gustaría hacer un input solo para números y otros solo para algunos signos, hay alguna manera de hacer que solo se puedan colocar números o símbolos para el cálculo? TRANSLATION: How do I limit the input? These making a calculator without graphical interface in Python and I would like to make an input only for numbers and others only for some signs, is there a way to make that only numbers or symbols can be placed for the calculation? EXPLANCION: Hola, quieres que tu calculadora realice operaciones básicas como sumar, restar, multiplicar, etc. Todo lo que tienes que hacer es configurar 3 entradas del usuario, dos de las cuales son números. Uno es un símbolo como +, -, * o /. Una vez que acepta estas entradas, todo lo que tiene que hacer es convertir la entrada en números enteros y agregarlos en una declaración de impresión. Utilice una instrucción if para realizar un seguimiento de la operación que desea realizar. Si símbolo == "+", use una función que tome esos valores como entrada y los combine. TRANSLATION: Hello, you want your calculator to perform basic operations such as adding, subtracting, multipling etc. All you have to do is set 3 inputs from the user, two of which are numbers. One is a symbol such as +, -, * or /. Once you accept these inputs, all you have do is convert the input to integers and add them in a print statement. Use a if statement to track the operation you want to perform. If symbol == "+", use a function which takes those values as input and combines them.
8th Oct 2021, 5:12 AM
Jibraeel Abdelwahhab
Jibraeel Abdelwahhab - avatar
+ 5
¿Puedo levantar el pulgar por favor si te ayudo? No hablo español, así que traduje toda esta conversación para responder la pregunta. ¡Gracias!
8th Oct 2021, 6:53 AM
Jibraeel Abdelwahhab
Jibraeel Abdelwahhab - avatar
+ 3
Jibraeel abdewahhab, en visual studio code se puede hacer? Lo esto haciendo ahí, gracias por tu ayuda
8th Oct 2021, 11:22 AM
Gabriel
Gabriel - avatar
+ 3
Thanks, the calculator I make is to learn Python, so I don't know anything, can you explain the code to me? If it's in English, nothing happens.
8th Oct 2021, 11:27 AM
Gabriel
Gabriel - avatar
+ 3
Gabriel Si quieres hacer operaciones matemáticas con el input, utiliza la función int(input()) o float(input()) dependiendo, si quieres que salga como fracción, utiliza float() si quieres que sea un número normal como, por ejemplo 2, utiliza int(), pero si quieres juntar palabras, te aconsejo que no hagas nada, a ver, por si no entendiste, te daré un ejemplo: print(input()+input()) El input sería "de" y el otro "Gabriel" La salida del código sería: deGabriel, si quisieras que saliera separado, te daré otra opción, las entradas serían las mismas: d = input() g = input() print(f"{d} {g}") La salida sería: de Gabriel. Espero que hayas entendido. Buena suerte con todo y cualquier duda pregunta. Bendiciones 👍.
8th Oct 2021, 8:34 PM
CGO!
CGO! - avatar
+ 2
Sí, puede poner varias entradas en sololearn. Todo lo que tienes que hacer es ponerlos en diferentes líneas. Así que pondrías 1 + 2 para una ecuación
8th Oct 2021, 6:52 AM
Jibraeel Abdelwahhab
Jibraeel Abdelwahhab - avatar
+ 2
Hello Rik wittkop, (not speak English), tanks tor you code
8th Oct 2021, 11:23 AM
Gabriel
Gabriel - avatar
+ 2
Gabriel The calculator I showed you uses a dictionary to define the operator. Once the operator is identified, the section of code associated with the key of the dictionary is enabled. When you learn about dictionaries later in your Python courses, you will be able to fully understand the concept. Take your time, I just wanted to show you a concept. 😁👍 PS: Can you give Best Answer to Jibraeel Abdelwahhab because he did all the hard work on your question
8th Oct 2021, 11:33 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Gabriel Later in the tutorial, you will learn about Try Except methods, which will allow you to control incorrect user input
8th Oct 2021, 8:23 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Gracias
9th Oct 2021, 8:54 AM
Gabriel
Gabriel - avatar
+ 2
Gabriel De nada
9th Oct 2021, 1:05 PM
CGO!
CGO! - avatar
+ 2
Gabriel De nada, cualquier duda, por mí, pregunta 👍👍 Como yo digo, preguntar es saber👍
10th Oct 2021, 7:59 PM
CGO!
CGO! - avatar
+ 1
Como se configuran las entradas de usuario?, Donde? Como? Se puede hacer en visual studio code? O solo desde Python?, Dejo todo el código de mi calculadora aquí: que tendría que añadir para hacer un input solo de números y otro solo de signos? https://code.sololearn.com/cda1mZ705UTI/?ref=app
8th Oct 2021, 6:41 AM
Gabriel
Gabriel - avatar
+ 1
Jibraeel Abdelwahhab I will raise a thumb for you. Good effort Well done 😁👍
8th Oct 2021, 11:01 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Gabriel Jibraeel Abdelwahhab has given you some great advice. May I show you a possibility? https://code.sololearn.com/cctAihtplABa/?ref=app
8th Oct 2021, 11:08 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Gabriel Tu ingles es mejor que mi español
8th Oct 2021, 11:25 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Tanks Rik, About the best question, I shouldn't even what it was, I changed it, a question if I put that code and fit it in mine, will I be able to limit the input as I wanted?
8th Oct 2021, 11:39 AM
Gabriel
Gabriel - avatar
+ 1
Gabriel Best question is awarded to the person who provides you with the most relevant / helpful answer. The recipient of Best Answer gets 10XP + 1XP for each upvote. Your question What do you mean by limit?
8th Oct 2021, 11:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik, I mean, instead of being able to place all the characters you can only place some: for example, that in an input you can only place numbers
8th Oct 2021, 11:46 AM
Gabriel
Gabriel - avatar
+ 1
Por lo que entiendo, quieres restringir el uso de ciertos caracteres por input. Para los 2 primeros que solo acepte números ya que si usas int(iput y metes una letra te manda error, creo que necesitas manejar los error (excepciones) haciendo uso de try, te dejo esto espero te sirva. el tema 8.3 gestionando excepciones https://docs.python.org/es/3/tutorial/errors.html
10th Oct 2021, 3:16 AM
Luis Alberto de la Cruz Díaz
Luis Alberto de la Cruz Díaz - avatar