user-input

Take user input in Python 2.7

人走茶凉 提交于 2019-12-04 07:23:10
问题 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() ) 回答1: Here is also a working code. class Student: def __init__(self,name,pref): self.name = name self.preference = pref student1=Student(raw_input(

How to stop a running method with keyboard input in a Console Application on C#?

自作多情 提交于 2019-12-04 07:09:47
In short, I'm utilizing C# to scientific computation and I've written a method that has a while loop that may run to a user-specified quantity of steps... Actually, this method may take too long to execute (like more than 5 hours). When it takes this long, I may want to stop the method pressing Esc key, for example. As I read something about breaking while , it is as simple as a Boolean flag or something like this. So I thought in something like this: public Double? Run(int n) { int i = 0; while ((i < n) && (/* inputkey != ConsoleKey.Escape */)) { // here goes the heavy computation thing //

java print a triangle

我们两清 提交于 2019-12-04 06:58:09
问题 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

PHP/MSSQL - Filtering from User Input (HTML)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:56:54
问题 I have been given this assignment, to include some sort of filtering to my current SQL query via User Input. Basically, i am looking for a filtering option, whether its some kind of menu or button, really doesn't matter. My mssql is as follows: SELECT TOP 10 Test_Database.Distributor, Test_Database.Value FROM Test_Database WHERE Test_Database.Week = '(USER INPUT GOES HERE)' GROUP BY Distributor ORDER BY Value desc How can i make the WHERE statement a User Input? For instance.. A client wants

What is an appropriate way to programmatically exit an application?

≯℡__Kan透↙ 提交于 2019-12-04 05:49:19
问题 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

python library for user input

寵の児 提交于 2019-12-04 05:40:41
I am implementing a small command line tool in python that needs to ask the user a couple of questions. I use raw_input('Are you male or female?') all the time. Now I would like to be able to deal with dumb users (or those too lazy to read/remember the documentation), so I need to check whether the answer makes sense. gender = '' while gender not in ['male', 'female']: gender = raw_input('Are you male or female?') I am wondering whether there exists something like argparse that would automate this problem, something like import inputparse gender = inputparse.get_input(prompt='Are you male or

Java - Assigning User Input to Variable / Change Counter

我们两清 提交于 2019-12-04 05:21:22
问题 I'm quite new to java, although I have a fairly basic knowledge of C++. For my assignment I am counting change and sorting it into American currency (i.e., if you had 105 cents, it would divide it into one dollar and one dime). Logically I understand how to do this, but I'm having some serious trouble understanding the java syntax. I'm having serious trouble to find a way to assign a user-inputted value to a variable of my creation. In C++ you would simply use cin, but Java seems to be a lot

What is the correct way to make web form input safe for a variety of contexts?

旧时模样 提交于 2019-12-04 03:18:35
What do you all think is the correct (read: most flexible, loosely coupled, most robust, etc.) way to make user input from the web safe for use in various parts of a web application? Obviously we can just use the respective sanitization functions for each context (database, display on screen, save on disk, etc.), but is there some general "pattern" for handling unsafe data and making it safe? Is there an established way to enforce treating it as unsafe unless it is properly made safe? Like it's already been said, there are several things to take into account when you are concerned about web

Strategy for tracking user recent activity

霸气de小男生 提交于 2019-12-04 03:09:48
Our customer would like to know who is online and currently using the custom application we wrote for them. I discussed it with them and this does not need to be exact , more of a guestimate will work. So my thought is a 15 minute time interval to determine user activity. Some ideas I have for doing this are as follows: Stamp their user record with a date and time of their last activity every time they do something that hits the database, or requests a web page ... this though could be quite database intensive. Send out a "who is online request" from our software, looking for responses, this

Safely executing user-submitted python code on the server

你。 提交于 2019-12-04 02:45:21
I am looking into starting a project which involves executing python code that the user enters via a HTML form. I know this can be potentially lethal ( exec ), but I have seen it done successfully in at least one instance . I sent an email off to the developers of the Python Challenge and I was told they are using a solution they came up with themselves, and they only let on that they are using "security features provided by the operating system" and that "the operating system [Linux] provides most of the security you need if you know how to use it." Would anyone know how a safe and secure way