New answers tagged

3

You can store your numbers in a list after taking them as input as a string separated by spaces, then splitting them into a list using the list.split() function and finally converting each of them to integers. input_string = input('Enter the numbers separated by space: ') list_of_numbers = [] for character in input_string.split(): list_of_numbers.append(...


7

Loops would be the perfect tool here to reduce duplication; although getting it exactly as you have will be difficult due to you currently spelling out numbers ("first", "second", "third"...). For the sake of simplicity, I'm going to ignore the numeric words, because producing those is non-trivial and a whole project on its own ...


2

The biggest problem in your code is keyCode. From MDN: Deprecated This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; ...


2

float vs. double Little reason to use float here, suggest double instead. Save float for selective space/speed issues - which are not present here. If code uses float variables, use float functions like sinf(), log10f(), powf(), ... than sin(), log10(), pow(). Printing floating point Rather than printf("%f", ans), print using "%g" or &...


3

Pi There are some dissenting opinions on this, but: most compilers offer an M_PI if they are configured to do so. I prefer to do that rather than defining my own. Implicit return types Leaving these return types implicit: load(); //Function Prototype Exit_0(); //Function Prototype main() { is not great. main should be int main. Exit_0 should be void. load ...


Top 50 recent answers are included