FAQ Database Discussion Community


How do I take Someone's name in Python and create a file to write to with that name?

python,python-2.7,user-input
I am a bit new to Python, and trying to do something simple I'm sure. I want to ask someone their name as the initial raw_input and then I want that name to be used to create a file. This is so that any additional raw_input taken from that user...

How do input characters into an array through user input?

java,arrays,char,user-input
This is essentially what i have, everything works fine, but for some reason I'm not able to input the characters into the array. If you could explain to me why it isn't working it would be greatly appreciated. The purpose of this is to input a series of characters into...

How to make sure that a user inputs a number? [duplicate]

python,validation,python-3.x,user-input
This question already has an answer here: Asking the user for input until they give a valid response 2 answers I've written a BMI calculator but I'd like there to be a way to ensure the user only types numbers so, if something else was input the question was...

How to implement stacked, table-like, text fields in iOS?

user-interface,ios8,xcode6,user-input
How this form is designed? It is a table view with borderless text inputs? I would like to reproduce this stacked form layout in my app, but not able to find any examples. https://www.dropbox.com/s/de1kk5vs5km1aao/Screenshot%202015-02-08%2021.03.57.png?dl=0...

Python 3.x error with methods asking for input error is TypeError: __init__() takes 0 positional arguments but 1 was given

python,oop,python-3.x,methods,user-input
I'm attempting utilizing TeamTreehouse learning subscription & this Starting Out With Programming Logic And Design (3rd Ed) book to attempt learning programming & Python. Please don't shoot to kill me I'm learning. Goal: I'm attempting to set a Pet class with 3 fields/attributes/properties. The class will have 2 methods, set...

Creating a Lottery

java,user-input
Generate a lottery of a three digit number. The program prompts the user to enter a three-digit number and determines whether the user wins according to the following rules: (RULE 1). If the user input matches the lottery number in the exact order, the award is $10,000. (RULE 2). If...

python - is it possible to enter user-chosen input and output files

python,user-input,stdin
I'm a newbie in python, so please bear with me. I don't know how to describe,so I'll just show an example. python CODE.py -i1 input1.txt -i2 input2.txt -o output.txt Is such thing possible with python? I've looked up for a while but haven't find an answer. Thank you!...

Java getText of looped multiple JTextFields

java,for-loop,jtextfield,user-input,getter
My first question here. Already got a lot of help but now I don't know how to do. My code: package view; import javax.swing.*; public class OptionPlayerNames { JPanel playerPanel = new JPanel(); JTextField playerNames = new JTextField(); public OptionPlayerNames() { for (int i = 0; i < 8; i++)...

PHP Vulnerability (XSS, …) > When can user input/url injection actually do harm?

php,security,variables,xss,user-input
Hope this question is not too unspecific, so... My question is, when do I actually have to pay attention on how I handle vulnerable variables and when do I not. E.g. it's obviously insecure to use something like ... echo $_POST['username']; // insecure !!! in your template. $_GET and $_SERVER...

Using a user input text string in R

r,web-scraping,user-input
I have a code that extracts data from a website using specific tags depending on the country entered. However, I want it so that the user inputs a country and then the appropriate details are extracted. The code I have is as follows: library(rvest) x <- readline(prompt = "Enter Country:...

Batch File - Error in FOR / IF statement with numbers and text

batch-file,if-statement,for-loop,user-input
These code was working before. I added some additional letters to the "FOR" line and now it's not working. Goal: Get user input. User input can be a number or letter. Set input as the "SELECTION". :choice1 A. 1-12 B. 1-7 1. stuff 2. more stuff etc to 7 C....

Standard way of retrieving PHP Form Inputs

php,forms,user-input
I have been doing web programming with PHP for about 2 months,and for forms, I have been retrieving user input in a manner such as this: For standard <input type="text">: /*input sanitation*/ function testInput($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysql_real_escape_string($data); return $data; }...

UITextField Caret stops moving around when too large

ios,objective-c,uitextfield,user-input,caret
UITextField allows you to override -caretRectForPosition: in subclasses. I want the caret to cover the text field's entire height. - (CGRect)caretRectForPosition:(UITextPosition *)position { CGRect inherited = [super caretRectForPosition:position]; inherited.origin.y = -50.0; inherited.size.height = 200.0; return inherited; } If I make it too large however (like in the example), it will...

Invalid operator type of std::istream?

c++,user-input,istream
So I'm trying to create a C++ program that reads in a list of numbers(where the user enters a list of 5 numbers separated by spaces) and prints out the reversed list. so far, this is what I have: #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #pragma warning(disable: 4996)...

Unable to have methods from one class use user input from another class in Java

java,class,methods,user-input,getter-setter
Hello everyone I am having a bit of an issue getting user input from one class to be used in another class' methods (when I try to use the data that was input either nothing shows up, or if something does all of the numbers are zeros). Here are the...

Regular Expression does not accept correct inputs

java,regex,error-handling,expression,user-input
I am developing a Java method, which checks, if the user input is valid. For that I wrote four regular expressions to check that. The first three work fine. The last one, the "most complex" regular expression, does not accept values, which should be accepted. I want to make sure,...

Creating a method to return an integer based on user string input

java,methods,user-input
I am not too great at java, but I'm trying to create a method that takes input from the user and returns a value. However difficulty always returns 0? chosenDifficulty = userName.next().toUpperCase(); public int getDifficulty() { int difficulty = 0; if (chosenDifficulty == "HUMAN") { difficulty = 1; if (chosenDifficulty...

tcsh check if file exists in a given path

user-input,absolute-path,tcsh
First of all, I am new to tcsh and I realize its disadvantages and why it is harmful (and I agree!). However, I don't have a choice and I am needing to write a tcsh script where the user provides a directory as input and the script will check if...

Python while loop to check for valid user input

python,while-loop,user-input
Python newbie here so sorry for what I'm sure is a stupid question, but I can't seem to solve the following challenge in a tutorial that is asking me to use a while loop to check for valid user input. (using Python2.7) Here's my code, but it's not working properly:...

How to add user input above code [duplicate]

java,loops,user-input,binary-search
This question already has an answer here: java console input 2 answers i want to get the user input from user and do non recursive binary search can any one show me how to do it it would be appreciated public class Main { // binarySeach: non-recursive public int...

Program that either waits for user input or runs at defined intervals?

python,multithreading,user-input,keyboard-events
I currently have a program that runs at regular intervals. Right now the program runs continuously, checking for new files every 30 minutes: def filechecker(): #check for new files in a directory and do stuff while True: filechecker() print '{} : Sleeping...press Ctrl+C to stop.'.format(time.ctime()) time.sleep(1800) However, I'd also like...

How to detect user input in a JFrame? (Java)

java,swing,jframe,user-input,greenfoot
Before you tell me to Google it, I have done, obviously. And most of the other questions asking same or similar things to this is very specific to their code that I can't seem to figure out how to put it in mine. So, anyway, I'm trying to make a...

scanf get multiple values at once

c,char,segmentation-fault,user-input,scanf
I need to get in one single shot different inputs from one single line. In particular I need to get a single char and then, depending on which char value I just read, it can be a string and an int or a string, an int and another string and...

Turn user input strings into a function call

function,python-2.7,user-input
I am in the process of writing a lexer for a text based game. A simplified example of what my code looks like this: class Character: def goWest(self, location): self.location == location.getWest() #getWest() would be defined in the location class x = raw_input("What action would you like to take") With...

Java User Interface Improvement

java,user-interface,recursion,error-handling,user-input
I have been trying to present this a little better to the user. I am trying to setup if he puts in the wrong input then he has to start over until he puts in the right numbers set between 0 and 9000. Its also an multiplication iteration and a...

Storing a string of inputs into a struct in C

c,string,struct,user-input,scanf
was wondering how I would be able to store a user inputted string in the format "string,character,integer,integer" into a struct. For example storing "apple,c,5,10" into typedef struct { char item[80]; char letter; int x,y; }information; information apple; I am trying to avoid going through using scanf and a long piece...

How to read an integer input from the user in Rust 1.0?

input,integer,rust,user-input
The answers google returns are all based on from_str (including the one here: http://stackoverflow.com/a/25632307/8127), but apparently from_str(x) has changed into x.parse() in Rust 1.0. As a newbie, it's not obvious how the original solution should be adapted taking this change into account. So, as of Rust 1.0, what is the...

jQuery choose file with a popup message not working

jquery,jquery-ui,user-input
I'm trying to add some popup message with a message ("make sure you are uploading a PDF file) to the user when they click on input[type=file] the problem is that the pop message is displayed too late. I'm getting the filesystem window before the popup message <input type="file" id="file" name=""...

Python function returning correct result but interpreter returning strange error

python,function,debugging,user-input
Python newbie here, so bear with me... I'm attempting to utilize the often poorly written Codeacademy Python tutorial, wherein the exercise challenge is to: Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number's digits. For example: digit_sum(1234) should...

C program skips a line when asking for user input [duplicate]

c,char,user-input,scanf
This question already has an answer here: C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf 6 answers printf("Number of tracks: "); fflush( stdin ); scanf("%d", &track); printf("Is this an album or single: "); fflush( stdin ); scanf("%c", &type); when I...

Excel VBA InputBox value is not a date

excel,vba,excel-vba,date,user-input
I have a user input box where you type in a string, annoyingly this string looks like a date 00/00/0000 and excel reformats it as such. When the value can't be a date ex. 18/19/4561 (month can't be 18 or 19) it displays it correctly. But whenever it can be...

If a location exist with os.path.isdir by passing a user input variable

python-2.7,scripting,user-input,os.path
My python code snippet is some what like this CLName = raw_input ("\n\nEnter 7 digits CL number !") if os.path.isdir("\\\\abc\\\Compiler_Builds\\\something\\\CLName"): print "CL Exists" \\\\abc\\Compiler_Builds\\something is a local windows server location. In the above code I want os.path.dir() to check if the path \\\\abc\\\Compiler_Builds\\\something exists by inserting CLName at end, which...

User input in asychronous Node.JS

javascript,node.js,asynchronous,user-input
In the following code, I want to get a Grid, ask for x and y. Then I'll get the Grid again. However, due to Node.JS being asynchronous, the second get gets executed after asking for x, before x is given and before y is asked. I should probably check if...

scanf issue when reading double

c,gcc,double,user-input,scanf
I'm using MinGW on windows 7 to compile C files. My problem is a strange behaviour with scanf() to read doubles from user input. My code: int main() { double radius = 0; double pi = 3.14159; scanf("%lf \n", &radius); // after the input, it continues waiting... radius = ((radius...

How can I make a textfield highlight in red only after its input is proven as incorrect?

javascript,html5,css3,user-input,background-color
I have this form (Horribly basic and messy at the moment, I know.): This is how it looks on-load. Here is my CSS: img { position: fixed; right: 100px; top: 100px; } input:invalid { background-color : #ff0000; } input:valid { background-color : #99ff99; } What I want to know is...

How to return from shell 'read' command passed in expect script?

linux,shell,ssh,user-input,expect
I am really new to using expect, and a bit confused regarding passing commands to an expect script, so please bear with me... I have searched numerous forums, but cannot seem to find an example of an expect script that uses the read command to get user input. In my...

Remove spaces from user input string in Python

python,string,whitespace,user-input
how can I remove whitespaces from within a user input string? Can't I use .replace(" ","")? it didn't work for me. My code: >>>p=raw_input ("Enter phrase:\n") >>>p.replace(" "."") It still outputs user input phrase WITH spaces..what am I doing wrong?Please help. ...

How do I create a function that allows for user input to have a different outcomes based on how many times the same input was entered in Python?

python,python-2.7,user-input
I am creating a text based adventure game in Python. At certain points there may be rooms with many different actions you can perform, like opening a chest. I want to create a single function that allows this, because right now I have to write all this: (Just an example)...

Open a file from user input in python 2.7

python,python-2.7,user-interface,user-input
How would I open a file by asking for user input? After raw_input("PROMPT") requests filename.txt from the user, I get the error code: TypeError: coercing to Unicode: need string or buffer, file found which tells me I need to convert the user input to a string, or format it a...

Recommended method for filtering input in VB.Net

vb.net,validation,user-input
I am trying to explain to my students how to filter and validate input in VB.Net. My question is, where is the best place to do it? If for example I was trying to limit numeric input to positive integers between 1 - 99, I could: 1. Use a Masked...

How to handle apostophes in user inputted String?

java,sql,validation,error-handling,user-input
So I'm making a program that takes user input from a GUI as a parameter. How do I handle it if the user inputs a word or sentence with an apostrophe? I'm using it to input something into a database, so for example: INSERT INTO users (firstname, lastname) VALUES ('"+firstNameString+"',...

Best way to get user to input items of different types into a list

python,list,user-input
What's the best way in Python to prompt a user to input items to an empty list and ensure the entries are evaluated to correct data types? For example user enters following mix of int, float, str and list item values: 24 190.45 'steve' 'steve smith' ['4A', '7B'] new_list becomes...

JavaScript Variables and User Input

javascript,jquery,html,css,user-input
Situation: Currently I have a search box utilizing jQuery’s autocomplete plugin that allows the user to search for a sport’s team and then once found select on a submit button where it appends the team as a list item (preferable functionality would be when the user clicks on the actual...

Java- Key Bindings not working / actionPerformed not being called

java,swing,graphics,user-input,key-bindings
I finally learned how to get graphics to work in java thanks to the guy who helped me on my previous question, but now I can't get key bindings to work. I know that the graphics method is called as I need it to, and I think that I have...

Dynamically allocate user inputted string

c,arrays,user-input,scanf,dynamic-memory-allocation
I am trying to write a function that does the following things: Start an input loop, printing '> ' each iteration. Take whatever the user enters (unknown length) and read it into a character array, dynamically allocating the size of the array if necessary. The user-entered line will end at...

print the result as soon as user input “done”

python,string,python-2.7,while-loop,user-input
largest_so_far = None smalest_so_far = None value = float(raw_input(">")) while value != ValueError: value = float(raw_input(">")) if value > largest_so_far: largest_so_far = value elif value == "done": break print largest_so_far I think problem with this is that done is string while input is float type. I have also tried it...

Non latin characters replace on .keyup() does not work when typing fast

javascript,jquery,user-input
I have jQuery code that replace Cyrillic user input with Latin chars. This work fine when user input is not too fast (60-70 chars per minute) but when user typing faster then this, it mixed Cyrillic chars and Latin chars, probably because cannot catch keyup event in time. How can...

if user start typing in textbox value change to input else if user didn't type any thing value change to an specific string in C#

c#,search,textbox,user-input
I have a listview and created a textbox to search itmes in that list! everything is ok about searching! but problem is I want my search box to be like this: at first Searchbox.Text="Search ..." and if user started typing in that searchbox change to that keyword! else(if) searchbox got...

Handling RuntimeExceptions in certain circumstances valid?

java,exception-handling,user-input
As I understand it from several tutorials, RuntimeExceptions are actually not supposed to be caught, because they shall reveal inappropiate usage of methods, especially APIs, correct? Furthermore, one might assume that the program is not able to recover from RuntimeExceptions. Now, I experienced a case where I might receive an...

Segmentation fault in hash function (C)

c,hash,struct,user-input
I decided that I wanted to make a program in C that would take a user input and do things with a hash table... well I have hit a snag and I am completely lost as to what is going on. When I run my code everything is fine until...

Validate case pattern (isupper/islower) on user input string

c++,user-input
I need to write a program that checks if the user-provided first and last names are correctly typed. The program needs to validate that only the first letter of each name part is uppercase. I managed to write code that checks the first character of the input. So I have...

Recursive function with same arguments

python,user-input,text-based
I'm creating a text-based game in python and have hit a road block. I have a function that checks if user input contains certain words, and if it does it returns the user-input, otherwise it will re-ask for the input. If you write something that doesn't contains one of the...

Input invisible c++ Maze Game

c++,user-interface,input,user-input
So I have most of my game finish up however, I want to save the score and name of the player to a text file and display it. So far the user input works and does save to a text file named score.txt however the input is invisible and you...

Windows Phone 8.1 ManipulationDelta Event

c#,windows,animation,windows-phone-8.1,user-input
I'm really confused about this Topic. None of the tutorials I found to e.g. move objects around when there's touch input works. For example they all do something like this: Control.AddHandler(UIElement.ManipulationStartedEvent, new EventHandler <ManipulationStartedEventArgs>(Control_ManipulationStarted), true); But there's no ManipulationStartedEventArgs, VS2013 can't find it and there's no way to add a...

Advancing text in a text file using user input

java,text,user-input
So in my first year of college for my christmas project I needed to make a basic game using if statements, I chose a text adventure but me being a novice I chose to write out every print out: System.out.println("You approach the two cupboards one on the right and one...

Simple InputBox function

function,powershell,user-input
I'm aware of a simple pop-up function for PowerShell, e.g.: function popUp($text,$title) { $a = new-object -comobject wscript.shell $b = $a.popup($text,0,$title,0) } popUp "Enter your demographics" "Demographics" But I am unable to find an equivalent for getting a pop-up to ask for input. Sure, there is Read-Line, but it prompts...

How to detect user inactivity time in python application (Linux)?

python,linux,user-input,putty,user-inactivity
I am wondering if there is any way that when I ask for user input, if there is a way to detect how many seconds have passed since asking for user input? I would like to be able to have some kind of timer, that if the user hasn't entered...

In Ruby, how can I print my next prompt on the same line after user input?

ruby,user-input
I'm tinkering with a basic Tower of Hanoi game, and trying to get user input twice, but print both prompts on the same line (separated by the first input). I've searched for awhile, maybe I'm using the wrong terms. I assume the new line is due to gets, or setting...

Unable to keep the static data for the input type fields in angular material

user-input,angular-material
How to make a default static value for input in material design? <input type="text" value="xyz" /> but in material design angular I am unable to keep the static value like value="xyz <md-input-container> <label>Start date</label> <input ng-model="agg.startDate" value="xyz"> </md-input-container>" value xyz is not affected in this case....

How do I change a user input variable?

bash,variables,user-input
Here is what I have echo "Please select an Environment " PS3="Please enter 1-6: " select env in dev qa test staging production quit do case $env in dev|qa|test|staging|production|quit) break ;; *) break ;; esac done echo $env What I want is when someone selects and env variable I want...

Stop user from typing before generated text

c#,wpf,richtextbox,user-input
I am writing a text editor in WPF (using C#) that simulates a chat program using a RichTextBox. When the user presses enter, the relevant username is automatically inserted on the next line. However, if the user types fast enough, alternating between enter and other key presses, their text can...

Can't receive user input within a switch statement

java,exception,switch-statement,user-input
I am just starting to write a menu which requires a user to choose which operation they want to carry out (like pages etc.). Once they have chosen the operation they need to be able to input with the keyboard to complete the task. The problem is that I am...

prompt for user input when running scala program with sbt

scala,command-line,sbt,user-input
I have a very simple scala program: object TakeInputs { def main(args: Array[String]) { val name = readLine("What is your name?") println(name) } } When I try to run this with sbt "project myproject" "run-main TakeInput" it doesn't wait for user input and the program just finishes with What is...

Access HTML form submitted value from a different javascript file?

javascript,html,forms,user-input
EDIT: Rephrased the question so that it is less ambiguous. I have two HTML files, x.html and y.html, and I have two javascript files, x.js and y.js. I have a form in x.html like so: <form action="y.html"> <input type="text" value="Blank." /> <br /> <input type="submit" /> </form> Note that x.html...