I have a line of code that is saying that there is invalid syntax in my print statement. Does anyone know about how to fix this? I've tried deleting the parentheses and have tried changing the +'s to ,'s.
print(stockName[random] + ' - $' + Names[0, amod] + ' : You have ' + x + ' of this stock')
If you use ' x ' with + operator it should be a string else you should use coma.
Related
I'm new to C++. I know a lot of python but I'm extremely new to C++. I was creating an array of chars but I got this error- "Too many Initializers" in VSCode.
Please let me know how to fix it.
Here's the code
1 | class Board {
2 | public:
3 | char pos_list[9];
4 |
5 | void reset_pos() {
6 | pos_list[9] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
7 | };
8 | };
I am getting this error in line 6.
Please help me :(
EDIT: My initial answer was not correct, please find the modified correct way to do what you are looking for:
You will not be able to use {'','',''} in order to assign empty values to all elements in the array in C++, you can only do that while initializing the array when you declare it. Also, it wouldn't be ideal because it would use hardcoding of ' ' across the entire length of the array. The better way to do this is to loop over the array and then set each element to empty like below:
void reset_pos() {
int len = sizeof(pos_list)/sizeof(pos_list[0]);
for(int i=0; i<len; i++){
pos_list[i] = ' ';
}
};
I'm using the function replace in a freemaker template like this:
example?replace("<|>|_|!", ' ', 'r')
The character '<' is not replaced. It can work with this ( I can't explain it=:
example?replace('<', ' ')
Any help ?
Thank you :)
trafficLightsCount =12
bufferDist = '5 mi. '
intersectionCount = 20
print 'Found', trafficLightCount, light in
the intersectionCount, buffer and, 'buffereDist 'intersections.'
a='something'
b=12
c='Another thing'
print 'Found : ' + '{0},{1},{2}'.format(a,b,c)
You will get the output : Found : something,12,Another thing
My formula works fine in most cases, but I need to stop it from adding the asterisk if the {SAMPLEPARAM.PA_NAME} = "Methylene Chloride". How can I achieve this behavior?
if {METHOD.ME_TYP} ='COFA'
then '* '+ {SAMPLEPARAM.PA_NAME}
else if (IsNull ({METHOD.ME_TYP}) or {METHOD.ME_TYP} = ' ')
then {SAMPLEPARAM.PA_NAME}
else {SAMPLEPARAM.PA_NAME}
If you want "Methylene Chloride" to not have an asterisk, all you have to do is tell the code to skip over if it finds that specific string.
At the same time, simplify your code by removing the part when you check {METHOD.ME_TYP}. There are three branches in your code, but the last two are the same. The ELSE IF does nothing useful:
IF ({METHOD.ME_TYP} = 'COFA') AND ({SAMPLEPARAM.PA_NAME} <> "Methylene Chloride")
THEN '* ' + {SAMPLEPARAM.PA_NAME}
ELSE {SAMPLEPARAM.PA_NAME}
I have a list of lists that i want to put in order with the times that a person leaves he's job. I already made a code to give me only the time but i need something to check the times and put them in order.
inFile=removeHeader(file_name) # the information is taken from a txt file and this only gives me the part of the services
#print inFile gives me list of lists like [['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']
for time in inFile:
hours=time[4]
print hours #this gives me only the hours they left work
see https://docs.python.org/2/library/functions.html#sorted
you have to sort the main list by the leave time i.e. the 5th value of the sublists, the key argument of sorted alows you to specify a function that will be called to compute keys the list is sorted based on:
import time
x =[['Peter', ' 06-CB-89', ' Xavier', ' 09:45', ' 10:15', ' downtown', ' 10', ' standby'], ['Robert', ' 13-KI-54', ' Paul', ' 09:30', ' 10:30', ' Castle', ' 45', ' standby']]
sorted(x, key = lambda x: x[4])