# Perform an action if N is within a pre-determined range

Advertisements I have a number generator/counter that will output increasingly higher values ranging from 1 to 1,000. Once it reaches 1,000, the count is reset and restarts. The total numbers generated between 1–1,000 is variable and random. The delta between numbers is variable and random. Example: 1, 45, 120, 300, 590, 700, 750, 967 3,… Read More Perform an action if N is within a pre-determined range

# Generating the sequence 0, 0, 1, 1, 0, 0, 1, 1, … in Python

Advertisements Using % 2 gives me the alternating sequence [0, 1, 0, 1, …] seq = [] for i in range(10): e = i % 2 seq.append(e) Is there a way to generate the sequence [0, 0, 1, 1, 0, 0, 1, 1,…] by generating the element from inside the loop? seq = [] for… Read More Generating the sequence 0, 0, 1, 1, 0, 0, 1, 1, … in Python

# Check if Large Float is Even or Odd

Advertisements I have tried using the modulo operator for small floats and it works perfectly fine. For example: 5 % 2 returns 1. But for other large floats that are read as exponential in python it just returns 0 every time even if the number is odd. Like this: 295147905179352825855 % 2 returns 0 even… Read More Check if Large Float is Even or Odd

# Inconsistent modulus result in python

Advertisements I’ve got a simple list "passage" that contains strings. Goal is to join these split words into lines of 5 words each. Using modulus 5 (against index value + 1 to simplify) as test of when to add a newline character. For reasons that escape me, it works fine, except when it suddenly decides… Read More Inconsistent modulus result in python

# Javascript show next prev content appenchild

Advertisements I have multiple divs with same class and I need put only one of class to some id, It show me not right order. And also if I will have some dropdown menu and I will click of some div with class, need to show this class in id. Here is my code, could… Read More Javascript show next prev content appenchild

# How to take a user input of 24 hour time in HHMM format? (without importing any modules)

Advertisements I need to accept a user input for time, between 0000 and 2359, without importing any modules. I currently have it just taking an int input: fillTime = "X" while fillTime == "X": try: fillTime = int(input("Enter the time (0000-2359): ")) if fillTime < 0 or fillTime > 2359: print("Error! Please enter a valid… Read More How to take a user input of 24 hour time in HHMM format? (without importing any modules)

# check if number is prime using recursion with only one parameter in c language

Advertisements I’ve got a task in my lesson to write a function that will check if a number is prime, it will return 1 if it is and 0 if it is not and all of that to do recursively. the function will look like that :int isPrime(int num); I’ve tried everything and searched everywhere… Read More check if number is prime using recursion with only one parameter in c language

# Find factorial n modulo m faster than O(n)

Advertisements How can I find (n!) % m faster than O(n)? 1 <= n <= 10^18, 1 <= m <= 10^6 >Solution : You can easily have O(m) time complexity in the worst case (when m is a prime) and it seems to be good enough since you have m <= 1e6 (while n can… Read More Find factorial n modulo m faster than O(n)

# Problems with input values to a list

Advertisements I’m quite new at this and I have a problem. I want to read an input and store it at a list, for example: 2 -> number of trees that will be formed after this all 2 -> number of nodes of the first tree 1 -> node 1 2 -> node 2 1… Read More Problems with input values to a list

# How to find the middle letter among the specified letters?

Advertisements I’ve created a function that accepts 2 parameters to find the middle value between those parameters in an Alphabet variable. Example: the middle part between Q and U is S, the middle part between R and U is ST, the middle part between T and Z is W, What I’m confused about is how… Read More How to find the middle letter among the specified letters?