int

Simple Python input error

喜欢而已 提交于 2019-12-22 04:12:37
问题 I'm trying to write a code to edit a list and make it a palindrome. Everything is working except my input still gives me one error. When I enter a non-int into get_number_2 , it crashes. def get_number(): num = raw_input("Please enter number between 100,000 and 1,000,0000: ") if not num.isdigit(): print "---------------------------" print "Invalid input: numbers only" print "---------------------------" my_main() else: return num def get_number_2(n): num = input("Please confirm the number you

What is the best column type for a United States ZIP code?

倖福魔咒の 提交于 2019-12-22 04:05:37
问题 I want to store Zip Code (within United States) in MySQL database. Saving space is a priority. which is better option using VARCHAR - limited to maximum length of 6 digit or using INT or using MEDIUM Int . The Zip code will not be used for any calculation. The Zip code will be used to insert (Once), Updated (if required) and Retrieved - Once (but it can be more than once) . Which is better option to use here VARCHAR or INT or MEDIUM IN MYSQL ? Please suggest anything else ? 回答1: There are a

Is scientific notation interpreted as int or float?

北战南征 提交于 2019-12-22 04:00:15
问题 If I hardcode a number in my code using the scientific notation (e.g. 1e9 ) what will the type of that number be (int, long, float, double..)? When the significand or the exponent are floating point numbers it can't be an integer obviously, but what in the above case? 回答1: The e makes it a floating-point literal. From the JLS (§3.10.2. Floating-Point Literals): A floating-point literal is of type float if it is suffixed with an ASCII letter F or f ; otherwise its type is double and it can

TypeError: unsupported operand type(s) for -: 'int' and 'list'

久未见 提交于 2019-12-22 03:57:19
问题 I'm trying to create a program in python that will tell you the day of the week you were born using the Zeller algorithm http://en.wikipedia.org/wiki/Zeller%27s_congruence but it's giving me this error TypeError: unsupported operand type(s) for -: 'int' and 'list' Why is that? date = raw_input ("Introduce here the day, month and year you were born like this: DDMMYYYY") if date.isdigit() and len(date) == 8: day = date[0:2] month = date[2:4] year = date[4:8] day = int(day) month = int(month)

Scala: How to force wrapping an integer as an object?

有些话、适合烂在心里 提交于 2019-12-22 03:42:12
问题 I am getting an error here: val a: Int = 1 val i: Int with Object = a How can I convert this 1 to an integer object in scala? My purpose is to pass it to an Array[Int with Object] . It currently displays the error: error type mismatch found : Int(1) required: Int with java.lang.Object val i: Int with Object = a ^ EDIT I have this error because I am using an android ArrayAdapter from scala, and therefore by defining: class ImageAdapter[T](ctx: Context, viewResourceId: Int, pointers: Array[T])

How to use something like the charAt for integers

六月ゝ 毕业季﹏ 提交于 2019-12-22 01:16:31
问题 I am trying to make a program that uses three digit numbers to identify items and I am trying to use something like the charAt method for integers or something. Im not too sure. Im a beginner and I apologize i just need help. Also I need a bit of help to use an if statement and relational operators. Im trying to do if the last digit in the number is less than 5 then it is {item} and if its greater than 5 then its this {item}. Something like that. Thank you so much in advance. String number;

How to convert an int so as to return the string which is how we say the int

烈酒焚心 提交于 2019-12-21 20:38:51
问题 I came across this interview question where the interviewer asked to write a function which will take an integer, say 123, and will return a string that would be how one would say that integer.In above case output should be "one hundred and twenty three".I have no idea how to solve these problems.Can anyone help in how to work out this problem? A pseudo code will be helpfull. 回答1: Use this Code for Converting Numbers to Word Source here public class YourNumberMyWord { public void pw(int n

Linux - Why doesn't a custom system call work properly with negative numbers?

房东的猫 提交于 2019-12-21 17:22:37
问题 I wrote a custom system call that compares two integers and returns the biggest one. Here's my kernel-side code: max.c #include <linux/kernel.h> #include <linux/syscalls.h> asmlinkage long sys_max(int num1, int num2) { if (num1 > num2) { return num1; } else { return num2; } } And here's my user-space code: max.h #include <unistd.h> #define SYS_MAX 323 int max(int num1, int num2) { int maxnumber = syscall(SYS_MAX, num1, num2); return maxnumber; } I'm using this little program to test the

Getting random numbers from a list of integers

孤者浪人 提交于 2019-12-21 09:57:28
问题 If I have a list of integers: List<int> myValues = new List<int>(new int[] { 1, 2, 3, 4, 5, 6 } ); How would I get 3 random integers from that list? 回答1: One simple way: Random r = new Random(); IEnumerable<int> threeRandom = myValues.OrderBy(x => r.Next()).Take(3); The better way: Fisher–Yates shuffle: public static class EnumerableExtensions { public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) { return source.Shuffle(new Random()); } public static IEnumerable<T> Shuffle<T>

Getting random numbers from a list of integers

自闭症网瘾萝莉.ら 提交于 2019-12-21 09:56:01
问题 If I have a list of integers: List<int> myValues = new List<int>(new int[] { 1, 2, 3, 4, 5, 6 } ); How would I get 3 random integers from that list? 回答1: One simple way: Random r = new Random(); IEnumerable<int> threeRandom = myValues.OrderBy(x => r.Next()).Take(3); The better way: Fisher–Yates shuffle: public static class EnumerableExtensions { public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) { return source.Shuffle(new Random()); } public static IEnumerable<T> Shuffle<T>