I know it's probably a duplicate but I didn't manage to find it. but anyways, every time I try to run my code in vscode, it exits normally with code=0, but it doesn't display anything at all on output. how can I fix this?
this is the simple code that I'm trying to run
from datetime import datetime
odds = [ 1, 3 , 5 , 7, , 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, ]
rightThisMinute = datetime.today().minute
if rightThisMinute in odds:
print("this minute seems a little odd!")
else:
print("not an odd minute.")`
and this is the output.
https://stackoverflow.com/questions/62461708/exited-with-code-0-in-0-074-seconds-output-window-has-no-output-in-visual-stud#:~:text=The%20reason%20you%20have%20been,while%20running%20the%20python%20program.&text=Then%20open%20the%20vscode%20and,to%20get%20the%20desired%20results.
This question might be helpful. As the answers already point out, you might have multiple extensions running on VSCode.
Also try simply printing Hello World to check if it works.
It is a problem with your list. It should look like this:
odds = [ 1, 3 , 5 , 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 ]
With the list above the code works fine for me. But please read about the modulo function. You really don't need a list of odd numbers.
if rightThisMinute % 2 == 0:
print("Even number")
else:
print("not an even number")
Related
I have this function:
def function(start_date_arrow=None,end_date_arrow=None, date_concept=None):
list=[getattr(date, date_concept) for date in arrow.Arrow.range(date_concept, start_date_arrow, end_date_arrow)]
This function works well when iterating over date_concept='month' and date_concept='day'. On the other hand, date_concept='year' only returns a list of one item.
For example:
start_date_arrow= arrow.get('2021-11-05')
end_date_arrow= arrow.get('2022-02-05')
year_list=function(start_date_arrow=start_date_arrow,end_date_arrow=end_date_arrow, date_concept='year')
year_list is [2021]
month_list=function(start_date_arrow=start_date_arrow,end_date_arrow=end_date_arrow, date_concept='month')
month_list is [11, 12, 1, 2]
day_list=function(start_date_arrow=start_date_arrow,end_date_arrow=end_date_arrow, date_concept='day')
day_list is [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
Second and third call are okei, but first one should return [2021,2022] instead of [2021].
Any idea of what is happening in the year call?
Found the issue.
If you use:
start_date_arrow= arrow.get('2021-11-05')
end_date_arrow= arrow.get('2022-02-05')
Year difference between both is less than 1, so it only returns the first one, so to return 2022 in the list end_date_arrow should be end_date_arrow= arrow.get('2022-11-05')
So I forced with an if statement the end date to be bigger just by one year, to force the return of both years.
I want to write a code that prints the first and last number within a list as well as 5 other points. The points have to be equidistant from each other as well. So the numbers outputted would be 25, 19, 29, 16, 20.
list_ = [25, 23, 14, 22, 19, 13, 12, 10, 28, 29, 11, 15, 18, 27, 16, 21, 20, 17, 24, 26]
Is this something you are looking for?
>>> size = len(lst)
>>> size // 5 # five elements starting with first one.
4
>>>
>>> for i in range(0, size, size//5):
print(lst[i])
25
19
28
18
20
I'm using sklearn to cluster some lines of text, but trying to understand the format of the returned cluster labels. It looks like this:
km_model.labels_
array([ 5, 35, 1, 29, 49, 2, 6, 28, 5, 4, 4, 19, 40, 52, 6, 20, 4,\n 40, 40, 7, 10, 13, 14, 4, 10, 29, 14, 22, 24, 13, 24, 5, 4, 21,\n ...
So it's kind of like an array but there are elements of \n to separate clusters?
Is that really the format?
Is this some type of shortcut method for packing matrices in SKLearn? Why don't they return a 2D array of labels, eg one list of labels per cluster?
After that what is the best way to iterate through this type of data and group the labels per cluster?
Your clusters are the number values, the index of each label corresponds to the index of the samples you passed into your model. I suspect the \n is resulting from whatever IDE you're using read this output.
I looked at this answer where they have a really smart solution to find the point where the maximum drawdown starts, and where the maximum drawdown has it's lowest point. However, according to Wikipedia this is not the end of the period (as is claimed in the answer). The end of the period is when you reach the same peak value you had before the drawdown period began.
This implies that the drawdown period does not have an end for the graph given in the answer I linked to. I'm trying to write a code that can solve this, for both cases {1) it has an end period, 2) it has no end period}.
If the period never ends, I just want it to return the last index of the array (so basically the length of the array), and if the period does indeed end, I want the correct index. Here is a simplified example where I've tried to solve the first case - when it has an end period:
import numpy as np
an_array = [21, 22, 23, 40, 19, 35, 37, 45, 42, 39, 28]
running_maximum = np.maximum.accumulate(an_array)
# running_maximum = [21, 22, 23, 40, 40, 40, 40, 45, 45, 45, 45]
bottom_index = np.argmax(running_maximum - an_array)
start_index = np.argmax(an_array[:bottom_of_period])
# bottom_index = 4, start_index = 3
difference = running_maximum - an_array
# difference = [0, 0, 0, 0, 21, 5, 3, 0, 3, 6, 17]
The reason I compute difference, is because it makes it easy to see that end_index=7. This is because the maximum drawdown is 21 at index 4, and since difference=0 again at index 7, that means I have gone past (or just reached) my peak again. I tried writing np.argmin(difference[bottom_index:]) to get the index, but of course this doesn't give me 7 since I slice the vector difference, it gives me 3 instead which is incorrect.
Any tips on how I could solve this, and also make it so it returns the last index in cases where there is no end period would be amazing.
I think this solves it;
import numpy as np
an_array = [21, 22, 23, 40, 19, 35, 37, 45, 42, 39, 28]
running_maximum = np.maximum.accumulate(an_array)
difference = running_maximum - an_array
bottom_index = np.argmax(difference)
start_index = np.argmax(an_array[:bottom_index])
if difference[bottom_index:].__contains__(0):
end_index = len(difference[:bottom_index]) + np.argmin(difference[bottom_index:])
else:
end_index = len(difference)
With the given example array, I get end_index = 7. If I change an_array[4]=39, the maximum drawback no longer has an end, and I get end_index = 11. Not sure if __contains__(0) is efficient though.
I am trying to program a Lotto simulator, where the code generates 6 random unique numbers out of 45 for about 1000 players where each player has a unique ID. I want to place it into an array that looks like this:
lotto[0...n-1][0...5]
Where [0...n-1] contains the players ID, and [0...5] their unique 6 game numbers.
So it should look something like this when printed
lotto[1][32, 34, 24, 13, 20, 8]
lotto[2][1, 27, 4, 41, 33, 17]
...
lotto[1000][6, 12, 39, 16, 45, 3]
What is the best way of doing something like this without actually merging the two arrays together?
As later on I want to use a merge-sort algorithm to then numerically order the game numbers for each player so it would look something like this without the players ID interfering with the game numbers.
lotto[1][8, 13, 20, 24, 32, 34]
lotto[2][1, 4, 17, 27, 33, 41]
So far I've got:
playerID = list(range(1, 1001))
playerNum = random.sample(range(1, 45), 6)
print(playerID + playerNum)
But that just prints and joins:
[1, 2, 3, ..., 1000, 32, 5, 19, 27, 6, 22]
Thanks for the help.
import random
n_players = 1000
lotto = [random.sample(range(1, 45), 6) for _ in range(n_players)]
OR
import random
n_players = 1000
tup = tuple(range(1, 45))
lotto = []
for _ in range(n_players):
lotto.append(random.sample(tup, 6))