user-input

Using isdigit for floats?

此生再无相见时 提交于 2019-11-27 05:42:22
问题 a = raw_input('How much is 1 share in that company? ') while not a.isdigit(): print("You need to write a number!\n") a = raw_input('How much is 1 share in that company? ') This only works if the user enters an integer , but I want it to work even if they enter a float , but not when they enter a string . So the user should be able to enter both 9 and 9.2 , but not abc . How should I do it? 回答1: Use regular expressions. import re p = re.compile('\d+(\.\d+)?') a = raw_input('How much is 1 share

Drag the Range of a UI Input Range Slider

大城市里の小女人 提交于 2019-11-27 05:17:16
问题 <---------[]=====================================[]--------> 0 10 90 100 I need an input range slider with two handles to select a range, and the ability to drag the range (the equals signs in the above diagram). So, in the above example, start=10 and end=90, and it is dragged left by shifting the entire line between the two handles: <[]=====================================[]------------------> 0 80 100 Now Start is 0 and End is 80, accomplished without dragging the handles. What library

How to supply stdin, files and environment variable inputs to Python unit tests?

一世执手 提交于 2019-11-27 03:57:35
How to write tests where conditions like the following arise: Test user Input. Test input read from a file. Test input read from an environment variable. It'd be great if someone could show me how to approach the above mentioned scenarios; it'd still be awesome if you could point me to a few docs/articles/blog posts which I could read. All three situations you've described are where you need to specifically go out of your way to ensure you are using loose coupling in your design. Do you really need to unit test Python's raw_input method? The open method? os.environ.get ? No. You need to set up

What does `scanf(“%*[^\\n]%*c”)` mean?

江枫思渺然 提交于 2019-11-27 03:42:22
I want to make a loop in C that, when the program asks for an integer and the user types a non-digit character, the program asks again for an integer. I just found the below code. but I don't understand what this means scanf("%*[^\n]%*c") . What does ^\n mean? What does the * before ^\n and c mean? /* This program calculate the mean score of an user 4 individual scores, and outputs the mean and a final grade Input: score1, score2,score2, score3 Output: Mean, FinalGrade */ #include <stdio.h> //#include <stdlib.h> int main(void){ int userScore = 0; //Stores the scores that the user inputs float

HTML input that takes only numbers and the + symbol

人盡茶涼 提交于 2019-11-27 03:18:58
问题 I am trying to build a custom text input for phone numbers that accepts only numbers and the plus (+) symbol; all other characters need to be discarded and not shown on the field. I am trying to do this using an event handler (onkeydown/onkeypress) and discarding inputs corresponding to other keys. However, I can't figure out a cross-browser way to do it. Here are the approaches that I have tried and don't work: Using the onkeypress event and looking at event.key to figure out which key was

Check if the input is a number or string in C++

不问归期 提交于 2019-11-27 02:57:22
问题 I wrote the following code to check whether the input(answer3) is a number or string, if it is not a number it should return "Enter Numbers Only" but it returns the same even for numbers. Please suggest me a solution. #include <iostream> #include <string> #include <typeinfo> #include <stdio.h> #include <stdlib.h> #include <ctype.h> using namespace std; int main () { string ques1= "Client's Name :"; string ques2 = "Client's Address :"; string ques3 = "Mobile Number :"; char answer1 [80];

Fix a character to text input box using javascript/jquery

a 夏天 提交于 2019-11-27 01:07:33
问题 I am looking for a way to 'fix' a dollar symbol $ to a text input box eg <input type="text" value="$" /> but make it not possible for the default value to be removed, so that whatever the user inputs, there is always a $ symbol 'prepending' input. Cheers 回答1: There is the possibility of a background-image but it's difficult to maintain, and doesn't react to font size changes, which makes it the less optimal choice IMO. A better way in my opionion would be: Put a <span>$</span> next to the

How to protect against diacritics such as Zalgo text

假装没事ソ 提交于 2019-11-27 00:21:44
问题 The character pictured above was tweeted a few months ago by Mikko Hyppönen, a computer security expert known for his work on computer viruses and TED talks on computer security. In respect for SO, I will only post an image of it, but you get the idea. It's obviously not something you'd want spreading around your website and freaking out visitors. Upon further inspection, the character appears to be a letter of the Thai alphabet combined with over 87 diacritics (is there even a limit?!). This

Why can't I enter a string in Scanner(System.in), when calling nextLine()-method?

佐手、 提交于 2019-11-26 22:22:36
问题 How does this program actually work...? import java.util.Scanner; class string { public static void main(String a[]){ int a; String s; Scanner scan = new Scanner(System.in); System.out.println("enter a no"); a = scan.nextInt(); System.out.println("no is ="+a); System.out.println("enter a string"); s = scan.nextLine(); System.out.println("string is="+s); } } The output is: enter the no 1234 no is 1234 enter a string string is= //why is it not allowing me to enter a string here? 回答1: .nextInt()

Python - Infinite while loop, break on user input

Deadly 提交于 2019-11-26 21:38:32
问题 I have an infinite while loop that I want to break out of when the user presses a key. Usually I use raw_input to get the user's response; however, I need raw_input to not wait for the response. I want something like this: print 'Press enter to continue.' while True: # Do stuff # # User pressed enter, break out of loop This should be a simple, but I can't seem to figure it out. I'm leaning towards a solution using threading, but I would rather not have to do that. How can I accomplish this?