user-input

Command line input in Python

回眸只為那壹抹淺笑 提交于 2019-12-02 20:05:18
Is it possible to run first the program then wait for the input of the user in command line. e.g. Run... Process... Input from the user(in command line form)... Process... It is not at all clear what the OP meant (even after some back-and-forth in the comments), but here are two answers to possible interpretations of the question: For interactive user input (or piped commands or redirected input) Use raw_input in Python 2.x, and input in Python 3. (These are built in, so you don't need to import anything to use them; you just have to use the right one for your version of python.) For example:

How to capture enter key being pressed on pages containing multiple forms?

南笙酒味 提交于 2019-12-02 17:39:37
I have inherited a web application where the usual ability to press return in any of the input fields has been disabled for the very good reason that the page contains multiple forms, and the application would not be able to determine (or, so I am told) which form to action. The application has been designed so there are no submit buttons (as in input type="submit") and, instead, the designers have gone for onclick handling. Here are two buttons that are defined on one of the pages, included for illustration <input type="button" value="LOGIN" name="btnLoginOk" onclick="submit(); />" <input

Limiting the number of characters of user input

只谈情不闲聊 提交于 2019-12-02 17:00:35
问题 I'm trying to limit # of characters a user can input. It's not like when user inputs abcde , and I limit the input length to be 3, and only abc is taken into account. Is there a way to physically limit user from inputting more than certain amount of characters? For example, if user trys to type 12345 , and if I limit it to 3 characters, only 123 gets typed. I've tried the following code: cin.width(5); cin >> n; But I've realized it doesn't physically limit the user input, but only limits the

Numeric comparison with user input always produces “not equal” result

守給你的承諾、 提交于 2019-12-02 14:10:19
问题 I want to get a number input by the user via input() and compare it with a specific value, i.e., 3 . However, I have the impression my if statement doesn't work. The comparison is always False . Start = input() if Start == 3: print ("successful") 回答1: Python 3 input function returns string. Try like this start = input("-->: ") if start == "3": print("successful") 回答2: Some things you could do on your own to get to the root of the problem: Ways to get to know the type of the object: print(type

user input value to use as decimal value python

笑着哭i 提交于 2019-12-02 13:56:38
问题 I am writing a python code where I ask the user for input and then I have to use their input to give the number of decimal places for the answer to an expression. userDecimals = raw_input (" Enter the number of decimal places you would like in the final answer: ") then I convert this to integer value userDecimals = int(userDecimals) then I write the expression, and I want the answer to have as many decimal places as the user input from UserDecimals, and I don't know how to accomplish this.

Java Homework user input issue [closed]

霸气de小男生 提交于 2019-12-02 13:27:57
I have a class assignment to read in data using Scanner. import java.util.Scanner; public class Project23 { public static void main(String[] args) { // Declarations and instantiations. Scanner scan = new Scanner(System.in); String any = ""; boolean more = false; double purchase = 0.0; // Ask if user would like to run program? System.out.print("Do you have any purchases? Y/N?: "); // Ready value into string. any = scan.nextLine(); System.out.println(); // If any is equal to y or Y it will set the value of more to true // this runs the while statement below. more = any.toUpperCase().equals("Y");

Take user input in Python 2.7

只愿长相守 提交于 2019-12-02 13:06:23
Below is a simple python 2.7 code using class and objects . class Student: def __init__(self,name,pref): self.name = name self.preference = pref student1=Student("Tom","cce") print(student1.name) print(student1.preference) How can this code be implemented so that the name and preference values( string ) are taken using user-input( raw_input() ) Here is also a working code. class Student: def __init__(self,name,pref): self.name = name self.preference = pref student1=Student(raw_input("enter name:"),raw_input("enter branch:")) print(student1.name) print(student1.preference) Here's an example:

java print a triangle

夙愿已清 提交于 2019-12-02 13:02:40
I'm trying to make a program that takes user input such how long should the triangle be and its direction. The problem I have is that it keeps adding more numbers to the program after I run it. For example State the length of the two sides (finish with -1): 5 Should the triangle face down (0) or up(1): 1 * ** *** **** ***** 2 Should the triangle face down (0) or up(1): 1 * ** *** **** ***** ****** ******* My code: import java.util.Scanner; public class Triangel { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Initierings variabler för triangelsida. double

What is an appropriate way to programmatically exit an application?

好久不见. 提交于 2019-12-02 12:44:22
I am evaluating user inputs as commands for my application. If the user presses Q , or q , and then hits enter, the application quits and execution terminates. Is there a proper context, or best practices on how to do that? I do not have any resources to release, or anything like that. Should I just use System.exit(0); ? Is there a recommended way to do that? As my first approach I do something like this: while (true){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Other logic goes here... if (br.readLine().equalsIgnoreCase("Q")){ System.exit(0); } } catch

Python Mechanize Error +

送分小仙女□ 提交于 2019-12-02 11:42:12
问题 I am new to python (done some java in the past). I recently decided to automate a process that takes me about 20 hours once a year. I need to login to a vendor's website, with a login form they have. That then loads a new form which I can select an order from, and then it loads yet another form I can submit an item number to. This then loads the page with sizes of the item and price per size, I take this information and put it into a spreadsheet. The row has columns based on number of sizes