input

Python - Check if a number is a square

孤街浪徒 提交于 2021-02-08 04:36:38
问题 I wrote a function that returns whether a number input is a square or not def is_square(n): if n<1: return False else: for i in range(int(n/2)+1): if (i*i)==n: return True else: return False I am confident that this code works. But when I did the test cases, example: test.expect( is_square( 4)) , it says that the value is not what was expected. 回答1: Your function doesn't actually work, as it will immediatley return False on the first non-square-root found. Instead you will want to modify your

Capture HID keyboard event

大兔子大兔子 提交于 2021-02-08 04:23:39
问题 The code below works fine for only one input device. Unfortunately I need to capture about 12 different HID devices (RFID readers), so I would like to know if does anyone know how to adapt the code to work with 12 different inputs? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <dirent.h> #include <linux/input.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/select.h> #include <sys/time.h> #include

Capture HID keyboard event

倾然丶 夕夏残阳落幕 提交于 2021-02-08 04:22:58
问题 The code below works fine for only one input device. Unfortunately I need to capture about 12 different HID devices (RFID readers), so I would like to know if does anyone know how to adapt the code to work with 12 different inputs? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <dirent.h> #include <linux/input.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/select.h> #include <sys/time.h> #include

UITextView UITextViewTextDidChangeNotification not being called on programmatic change of the text

五迷三道 提交于 2021-02-08 03:38:30
问题 I call this in the init of a custom UITextView: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:self]; The method textChanged is not called when I programmatically set textView.text = @"" Any Ideas on what I am doing wrong? 回答1: Your shouldn't pass self to the last parameter, this parameter is notificationSender, it means that you just want to observer the notifications sent by self . Observer like this: [

Put A String In A ifstream Method [duplicate]

匆匆过客 提交于 2021-02-07 22:01:49
问题 This question already has an answer here : No matching function - ifstream open() (1 answer) Closed 5 years ago . I'm learning C++ and i'm getting some troubles when i'm trying to use a String in a ifstream method, like this: string filename; cout << "Enter the name of the file: "; cin >> filename; ifstream file ( filename ); Here is the full code: // obtaining file size #include <iostream> #include <fstream> using namespace std; int main ( int argc, char** argv ) { string file; long begin

Special characters appearing as question marks

懵懂的女人 提交于 2021-02-07 19:15:05
问题 Using the Python programming language, I'm having trouble outputting characters such as å, ä and ö. The following code gives me a question mark (?) as output, not an å: #coding: iso-8859-1 input = "å" print input The following code lets you input random text. The for-loop goes through each character of the input, adds them to the string variable a and then outputs the resulting string. This code works correctly; you can input å, ä and ö and the output will still be correct. For example, "år"

Special characters appearing as question marks

天大地大妈咪最大 提交于 2021-02-07 19:09:44
问题 Using the Python programming language, I'm having trouble outputting characters such as å, ä and ö. The following code gives me a question mark (?) as output, not an å: #coding: iso-8859-1 input = "å" print input The following code lets you input random text. The for-loop goes through each character of the input, adds them to the string variable a and then outputs the resulting string. This code works correctly; you can input å, ä and ö and the output will still be correct. For example, "år"

C++ input validation

别来无恙 提交于 2021-02-07 18:01:59
问题 I am beginning C++ programming, and have to do a lot of input validation. I have found this function that seems universally applicable, but am having trouble with one aspect; If I were to type -90, the program doesn't give an error. my question(s) are: 1. How can I add the circumstance that input cannot be <= 0? 2. Is there a better way to limit users input? Maybe a library within C++? Thank you for any help, or advice. #include <ios> // Provides ios_base::failure #include <iostream> //

Checking user input using isnan function of NumPy

安稳与你 提交于 2021-02-07 14:20:21
问题 I'm trying to use NumPy to check if user input is numerical. I've tried using: import numpy as np a = input("\n\nInsert A: ") if np.isnan(a): print 'Not a number...' else: print "Yep,that's a number" On its own t works fine, however when I embed it into a function such as in this case: import numpy as np def test_this(a): if np.isnan(a): print '\n\nThis is not an accepted type of input for A\n\n' raise ValueError else: print "Yep,that's a number" a = input("\n\nInsert A: ") test_this(a) Then

input() vs sys.stdin.read()

狂风中的少年 提交于 2021-02-07 13:44:00
问题 import sys s1 = input() s2 = sys.stdin.read(1) #type "s" for example s1 == "s" #False s2 == "s" #True Why? How can I make input() to work properly? I tried to encode/decode s1 , but it doesn't work. Thank you. 回答1: If you're on Windows, you'll notice that the result of input() when you type an 's' and Enter is "s\r" . Strip all trailing whitespace from the result and you'll be fine. 回答2: You didn't say which version of Python you are using, so I'm going to guess you were using Python 3.2