matplotlib.dates loadtxt converters date conversion python 2 - date

i am using juypter notebook and python 2.using matplotlib.dates I am unable to access the date
def bytespdate2num(fmt,encoding = 'utf-8'):
strconverter = mdates.strpdate2num(fmt)
def bytesconverter(b):
s = b.decode(encoding)
return strconverter(s)
return bytesconverter
Date,Open,High,Low,Close,Adjusted_close,Volume = np.loadtxt('C:\Users\harsh\Desktop\stock.txt', delimiter=',', unpack=True, converters ={0: bytespdate2num('%Y%m%d')})def bytespdate2num(fmt,encoding = 'utf-8'):
strconverter = mdates.strpdate2num(fmt)
def bytesconverter(b):
s = b.decode(encoding)
return strconverter(s)
return bytesconverter
Date,Open,High,Low,Close,Adjusted_close,Volume = np.loadtxt('C:\Users\harsh\Desktop\stock.txt', delimiter=',', unpack=True, converters ={0: bytespdate2num('%Y%m%d')})
the error message is:
> ValueErrorTraceback (most recent call last) <ipython-input-19-f69b316ac453> in <module>()
> 5 return strconverter(s)
> 6 return bytesconverter
> ----> 7 Date,Open,High,Low,Close,Adjusted_close,Volume = np.loadtxt('C:\Users\harsh\Desktop\stock.txt', delimiter=',',
> unpack=True, converters ={0: bytespdate2num('%Y%m%d')})
>
> C:\Users\harsh\Anaconda2\lib\site-packages\numpy\lib\npyio.pyc in
> loadtxt(fname, dtype, comments, delimiter, converters, skiprows,
> usecols, unpack, ndmin) 1022 1023 # Convert each
> value according to its column and store
> -> 1024 items = [conv(val) for (conv, val) in zip(converters, vals)] 1025 # Then pack it according to
> the dtype's nesting 1026 items = pack_items(items,
> packing)
>
> <ipython-input-19-f69b316ac453> in bytesconverter(b)
> 3 def bytesconverter(b):
> 4 s = b.decode(encoding)
> ----> 5 return strconverter(s)
> 6 return bytesconverter
> 7 Date,Open,High,Low,Close,Adjusted_close,Volume = np.loadtxt('C:\Users\harsh\Desktop\stock.txt', delimiter=',',
> unpack=True, converters ={0: bytespdate2num('%Y%m%d')})
>
> C:\Users\harsh\Anaconda2\lib\site-packages\matplotlib\dates.pyc in
> __call__(self, s)
> 287 return value: a date2num float
> 288 """
> --> 289 return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6]))
> 290
> 291
>
> C:\Users\harsh\Anaconda2\lib\_strptime.pyc in
> _strptime_time(data_string, format)
> 476
> 477 def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
> --> 478 return _strptime(data_string, format)[0]
>
> C:\Users\harsh\Anaconda2\lib\_strptime.pyc in _strptime(data_string,
> format)
> 330 if not found:
> 331 raise ValueError("time data %r does not match format %r" %
> --> 332 (data_string, format))
> 333 if len(data_string) != found.end():
> 334 raise ValueError("unconverted data remains: %s" %
>
>
> ValueError: time data u'2017-07-26' does not match format '%Y%m%d'

Related

Integer encoding format

I've run across some PIN encoding which I'm trying to figure out so I can improve upon a web application used at my place of work.
When I reset users' PINs (in this case, just my own for testing purposes), I'm seeing the following:
PIN VALUE
000000 = 7F55858585858585
111111 = 7F55868686868686
222222 = 7F55878787878787
999999 = 7F558E8E8E8E8E8E
000001 = 7F01313131313132
000011 = 7F55858585858686
000111 = 7F01313131323232
001111 = 7F55858586868686
011111 = 7F01313232323232
000002 = 7F02323232323234
100000 = 7F01323131313131
111112 = 7F03343434343435
123456 = 7F0738393A3B3C3D
654321 = 7F073D3C3B3A3938
1357924680 = 7F01323436383A3335373931
1111111111 = 7F5586868686868686868686
1234567890 = 7F0132333435363738393A31
It's clearly just hex, and always starts with 7F (1111111 or 127), but I'm not seeing a pattern for how the next two characters are chosen. Those two characters seem to be the determining value for converting the PIN.
For example:
000000 = 7F 55 858585858585
7F (hex) = 127 (dec) or 1111111 (bin) ## appears to not be used in the calculation?
55 (hex) = 85 (dec) or 1010101 (bin)
0 (PIN) + 85 = 85
000000 = 858585858585
111111 = 7F 55 868686868686
7F (hex) = 127 (dec) or 1111111 (bin) ## appears to not be used in the calculation?
55 (hex) = 85 (dec)
1 (PIN) + 85 = 86
111111 = 868686868686
But then also:
1357924680 = 7F 01 323436383A3335373931
01 (hex) = 31 (dec) ?
1 (PIN) + 31 = 32
1357924680 = 323436383A3335373931
Any help pointing me in the right direction would be greatly appreciated.
I don't see enough data in your minimal reproducible example to uncover an algorithm how the pinshift value should be determined (supplied to the pin_to_hex function). A random value is used in the following solution:
def hex_to_pin( pinhex: str) -> list:
'''
decode a PIN from a particular hexadecimal-formatted string
hex_to_pin('7F0738393A3B3C3D')
inverse of the "pin_to_hex" function (any of the following):
hex_to_pin(pin_to_hex('123456', 7))
pin_to_hex(*hex_to_pin('7F0738393A3B3C3D'))
'''
xxaux = bytes.fromhex(pinhex)
return [bytes([x - xxaux[1] for x in xxaux[2:]]).decode(),
xxaux[1]]
def pin_to_hex( pindec: str, pinshift: int, upper=False) -> str:
'''
encode a PIN to a particular hexadecimal-formatted string
pin_to_hex('123456', 7)
inverse of the "hex_to_pin" function (any of the following):
pin_to_hex(*hex_to_pin('7F0738393A3B3C3D'),True)
hex_to_pin(pin_to_hex('123456', 7))
'''
shift_ = max( 1, pinshift % 199) ## 134 for alpha-numeric PIN code
retaux = [b'\x7F', shift_.to_bytes(1, byteorder='big')]
for digit_ in pindec.encode():
retaux.append( (digit_ + shift_).to_bytes(1, byteorder='big'))
if upper:
return (b''.join(retaux)).hex().upper()
else:
return (b''.join(retaux)).hex()
def get_pin_shift( pindec: str) -> int:
'''
determine "pinshift" parameter for the "pin_to_hex" function
currently returns a random number
'''
return random.randint(1,198) ## (1,133) for alpha-numeric PIN code
hexes = [
'7F01323436383A3335373931',
'7F0738393A3B3C3D',
'7F558E8E8E8E8E8E'
]
print("hex_to_pin:")
maxlen = len( max(hexes, key=len))
deces = []
for xshex in hexes:
xsdec = hex_to_pin( xshex)
print( f"{xshex:<{maxlen}} ({xsdec[1]:>3}) {xsdec[0]}")
deces.append(xsdec[0])
import random
print("pin_to_hex:")
for xsdec in deces:
xsshift = get_pin_shift( xsdec)
xshex = pin_to_hex( xsdec, xsshift)
print( f"{xshex:<{maxlen}} ({xsshift:>3}) {xsdec}")
Output SO\71875753.py
hex_to_pin:
7F01323436383A3335373931 ( 1) 1357924680
7F0738393A3B3C3D ( 7) 123456
7F558E8E8E8E8E8E ( 85) 999999
pin_to_hex:
7f1041434547494244464840 ( 16) 1357924680
7f4e7f8081828384 ( 78) 123456
7f013a3a3a3a3a3a ( 1) 999999

getting __init__() got an unexpected keyword argument 'outputCols' when doing the oneHotEncoder

stages = []
for categoricalCol in categoricalColumns:
stringIndexer = StringIndexer(
inputCol=categoricalCol, outputCol=categoricalCol + "Index"
)
encoder = OneHotEncoder(
inputCols=[stringIndexer.getOutputCol()],
outputCols=[categoricalCol + "classVec"],
)
stages += [stringIndexer, encoder]
label_stringIdx = StringIndexer(inputCol="Status", outputCol="label")
stages += [label_stringIdx]
assemblerInputs = [c + "classVsc" for c in categoricalColumns] + numericColumns
assembler = VectorAssembler(inputCols=assemblerInputs, outputCol="features")
stages += [assembler]
> TypeError
> Traceback (most recent call last) <ipython-input-18-7156eaeec61b> in <module>
> 2 for categoricalCol in categoricalColumns:
> 3 stringIndexer = StringIndexer(inputCol = categoricalCol, outputCol = categoricalCol + 'Index')
> ----> 4 encoder = OneHotEncoder(inputCols=[stringIndexer.getOutputCol()], outputCols=[categoricalCol + "classVec"])
> 5 stages += [stringIndexer, encoder]
> 6 label_stringIdx = StringIndexer(inputCol = 'Status', outputCol = 'label')
>
> /usr/local/spark/python/pyspark/__init__.py in wrapper(self, *args, **kwargs)
> 102 raise TypeError("Method %s forces keyword arguments." % func.__name__)
> 103 self._input_kwargs = kwargs
> --> 104 return func(self, **kwargs)
> 105 return wrapper
> 106
>
> TypeError: __init__() got an unexpected keyword argument 'outputCols'
Check the documentation:
https://spark.apache.org/docs/2.2.2/api/python/pyspark.ml.html?highlight=onehotencoder#pyspark.ml.feature.OneHotEncoder
The param is outputCol

How is capacity increased in StringBuffer?

We know that StringBuffer's default capacity is 16 and when we try to add 17th char it will be increased by following rule:
newCapacity = (current capacity + 1) *2;
StringBuffer sb = new StringBuffer();
sb.append("aaaaaaaaaaaaaaaa"); // length is 16
System.out.println(sb.capacity()); // it gives 16
If I add 17th char
StringBuffer sb = new StringBuffer();
sb.append("aaaaaaaaaaaaaaaaa"); // length is 17
System.out.println(sb.capacity()); // it gives 34
But confusing part is now
If I try to add 35 chars
StringBuffer sb = new StringBuffer();
sb.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); // length is 35
System.out.println(sb.capacity()); // it gives 35
capacity should have been increased by 70 at this point of time.
Interesting part is
StringBuffer sb = new StringBuffer();
sb.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); // length is 34
sb.append("a"); // added 35th char
System.out.println(sb.capacity()); // it gives 70 which is correct
Can any one shed some light on this ?
The expandCapacity in StringBuffer does:
int newCapacity = value.length * 2 + 2;
if (newCapacity - minimumCapacity < 0)
newCapacity = minimumCapacity;
Since value.length is 16 at that time in your 35 example, it will use 35 (given in minimumCapacity). In the last example however, during the last append the value.length is 34 and minimumCapacity is 35, so new capacity will be value.length * 2 + 2.
The specifics may depend slightly on JDK version, but on my local version of 1.8.0_66:
public AbstractStringBuilder append(String str) {
if (str == null)
return appendNull();
int len = str.length();
ensureCapacityInternal(count + len);
str.getChars(0, len, value, count);
count += len;
return this;
}
private void ensureCapacityInternal(int minimumCapacity) {
if (minimumCapacity - value.length > 0)
expandCapacity(minimumCapacity);
}
void expandCapacity(int minimumCapacity) {
int newCapacity = value.length * 2 + 2;
if (newCapacity - minimumCapacity < 0)
newCapacity = minimumCapacity;
if (newCapacity < 0) {
if (minimumCapacity < 0) // overflow
throw new OutOfMemoryError();
newCapacity = Integer.MAX_VALUE;
}
value = Arrays.copyOf(value, newCapacity);
}
Note that value.length is actually capacity, not the length of the string being stored. The number of characters currently in the buffer is count! Also recall that value.length is initially 16, when calling new StringBuffer(). With those things in mind, let's do a little bit of stack tracing for each of the cases you presented.
For a string of size 17:
sb.append("12345678901234567")
if (str == null) -> false
len = 17;
ensureCapacityInternal(0 + 17)
if (17 - 16 > 0) -> true
expandCapacity(17)
newCapacity = 16 * 2 + 2 = 34
if (34 - 17 < 0) -> false
value = Arrays.copyOf("", 34)
str.getChars(0, 17, "", 17)
return this
sb.build() -> "12345678901234567"
sb.capacity() -> 34
For a string of size 35:
sb.append("12345678901234567890123456789012345")
if (str == null) -> false
len = 35;
ensureCapacityInternal(0 + 35)
if (35 - 16 > 0) -> true
expandCapacity(35)
newCapacity = 16 * 2 + 2 = 34
if (34 - 35 < 0) -> true
newCapacity = 35
value = Arrays.copyOf("", 35)
str.getChars(0, 35, "", 35)
return this
sb.build() -> "12345678901234567890123456789012345"
sb.capacity() -> 35
Note that the difference comes on the if (newCapacity - minimumCapacity < 0) line. If a string is appended that is longer than oldCapacity * 2 + 2, then newCapacity will be set to the length of the string to be appended.
In other words, when appending, if the buffer is not big enough to hold the existing text plus the appended text, it will check if (roughly) doubling in size would hold the new text. If that is still not enough, rather than recursively expanding, it will expand to exactly big enough.
This doesn't only happen with 35, though with strings much longer than that you probably wouldn't be running into the case where what you're appending is more than twice as long as your current capacity.
You would also see the same "length = capacity" if you were to do, say
StringBuffer sBuffer = new StringBuffer();
sBuffer.append("1234567890123456");
System.out.println(sBuffer.capacity()); // 16
sBuffer.append("1234567890123456789");
System.out.println(sBuffer.capacity()); // 35
But not
StringBuffer sBuffer = new StringBuffer();
sBuffer.append("1234567890123456");
System.out.println(sBuffer.capacity()); // 16
sBuffer.append("123456789012345678");
System.out.println(sBuffer.capacity()); // 34
sBuffer.append("1");
System.out.println(sBuffer.capacity()); // 70

Button should set the text in the webpage. What to do?

I am having problem in using button with function. I know only about java application and I am trying to learn HTML and JavaScript. I want the button to set the text present in conditional statement on to the webpage and conditions are based on select box.
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>P-Block Chemical Reactions</TITLE>
</HEAD>
<BODY>
<CENTER><FONT FACE="TIMES NEW ROMAN" COLOR="GREEN" size="50"><b><u>P-Block Chemical Reactions</u></b></font>
<br><br><br><h2>Structure of P-Block</h2><br>
<img src="http://2.bp.blogspot.com/-HNGbTyDrWso/UAGMqI2uY6I/AAAAAAAAAC0/mSWX5ZivvDk/s1600/Use%252Bnowwwww-723799.jpg">
<br></center>
<br>
<form>
<select id="Groups" name="Groups" >
<option value="1">Group 13</option>
<option value="2">Group 14</option>
<option value="3">Group 15</option>
<option value="4">Group 16</option>
<option value="5">Group 17</option>
<option value="6">Group 18</option></select>
<button onClick="gr();">See</button></form>
<script type="text/javascript">
function gr()
{
var s = document.getElementById('Groups');
var g = s.options[s.selectedIndex].value;
if (g === 1)
{
document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with O < sub > 2 < /sub> <br>
Boron is unreactive in crystalline form.Aluminium forms a very thin oxide layer on the surface which protects the metal from further attack. < br > < br >
2E(s) + 3O < sub > 2 < /sub>(g) → 2E<sub>2</sub > O < sub > 3 < /sub>(s)
(E = element) < br > < br >
< li > Reaction with N < sub > 2 < /sub><br>
With dinitrogen at high temperature these elements form nitrides. < br > < br >
2E(s) + N < sub > 2 < /sub>(g) → 2EN(s)
(E = element) < br > < br >
< li > Reaction with acids and alkalies < br >
Boron does not react with acids and alkalies even at moderate temperature, but aluminium dissolves in mineral acids and aqueous alkalies and thus shows amphoteric character. < br > Aluminium dissolves in dilute HCl and liberates dihydrogen. < br > < br >
2Al(s) + 6HCl(aq) → 2Al < sup > 3 + < /sup>(aq) + 6Cl<sup>-</sup > (aq) < br > < br >
However, concentrated nitric acid renders aluminium passive by forming a protective oxide layer on the surface. < br > < br >
Aluminium also reacts with aqueous alkali and liberates dihydrogen. < br > < br >
2Al(s) + 2NaOH(aq) + 6H < sub > 2 < /sub>O(l) → 2Na<sup>+</sup > [Al(OH) < sub > 4 < /sub>]<sup>-</sup > (aq) + 3H < sub > 2 < /sub>(g) <br><br>
< li > Reaction with halogens < br >
These elements react with halogens to form trihalides (except TlI < sub > 3 < /sub>).<br><br>
2E(s) + 3X < sub > 2 < /sub>(g) → 2EX<sub>3</sub > (s) & nbsp; & nbsp; & nbsp; & nbsp; (X = F, Cl, Br, I)
< /ul>");
}
else if (item === 2)
{
document.write("<b><h3>Chemical Reactions for GROUP 14 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with O < sub > 2 < /sub> <br>
All members when heated in oxygen form oxides.There are mainly two types of oxides, i.e., monoxide and dioxide of formula MO and MO < sub > 2 < /sub> respectively. SiO only exists at high temperature. Oxides in higher Oxidation states of elements are generally more acidic than those in lower oxidation states.<br><br> The dioxides : CO<sub>2</sub > , SiO < sub > 2 < /sub> and GeO<sub>2</sub > are acidic, whereas SnO < sub > 2 < /sub> and PbO<sub>2</sub > are amphoteric in nature.Among monoxides, CO is neutral, GeO is distinctly acidic whereas SnO and PbO are amphoteric. < br > < br >
< li > Reaction with water < br >
Carbon, silicon and germanium are not affected by water.Tin decomposes steam to form dioxide and dihydrogen gas. < br > < br >
Sn + 2H < sub > 2 < /sub>O → SnO<sub>2</sub > + 2H < sub > 2 < /sub> <br><br>
Lead is unaffected by water, probably because of a protective oxide film formation. < br > < br >
< li > Reaction with halogen < br >
These elements can form halides of formula MX < sub > 2 < /sub> and MX<sub>4</sub > (where X = F, Cl, Br, I).Except carbon, all other members react directly with halogen under suitable condition to make halides.Most of the MX < sub > 4 < /sub> are covalent in nature. The central metal atom in these halides undergoes sp<sup>3</sup > hybridisation and the molecule is tetrahedral in shape.Exceptions are SnF < sub > 4 < /sub> and PbF<sub>4</sub > , which are ionic in nature. < br > PbI < sub > 4 < /sub> does not exist because Pb-I bond initially formed during the reaction does not release enough energy to unpair 6s<sub>2</sub > electrons and excite one of them to higher orbital to have four unpaired electrons around lead atom.Heavier members Ge to Pb are able to make halides of formula MX < sub > 2 < /sub>. Stability of dihalides increases down the group. Considering the thermal and chemical stability, GeX<sub>4</sub > is more stable than GeX < sub > 2 < /sub>, whereas PbX<sub>2</sub > is more than PbX < sub > 4 < /sub>. Except CCl<sub>4</sub > , other tetrachlorides are easily hydrolysed by water because the central atom can accomodate the lone pair of electrons from oxygen atom of water in d orbital.
< /ul><br><br>");
}
else if (item === 3)
{
document.write("<b><h3>Chemical Reactions for GROUP 15 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
All the elements of Group 15 form hydrides of the type EH < sub > 3 < /sub> where E = N, P, As, Sb or Bi.<br> The stability of hidrides decreases from NH<sub>3</sub > to BiH < sub > 3 < /sub> which can be observed from their bond dissociation enthalpy. Consequently,the reducing character of the hydrides increases. Ammonia is only a mild reducing agent while BiH<sub>3</sub > is the strongest reducing agent amongst all the hydrides.Basicity also decreases in the order NH < sub > 3 < /sub> > PH<sub>3</sub > & gt; AsH < sub > 3 < /sub> > SbH<sub>3</sub > & ge; BiH < sub > 3 < /sub>.<br><br>
< li > Reaction with Oxygen < br >
All these elements form two types of oxides: E < sub > 2 < /sub>O<sub>3</sub > and E < sub > 2 < /sub>O<sub>5</sub > .The oxide in the higher oxidation state of the element is more acidic than that of lower oxidation state.Their acidic character decreases down the group.The oxides of the type E < sub > 2 < /sub>O<sub>3</sub > of nitrogen and phosphorus are purely acidic, that of arsenic and antimony amphoteric and those of bismuth is predominantaly basic. < br > < br >
< li > Reaction with Halogen < br >
These elements react to form two series of halides: EX < sub > 3 < /sub> and EX<sub>5</sub > .Nitrogen does not form pentahalide due to non - availability of the d - orbitals in its valence shell.Pentahalides are more covalent than trihalides.All the trihalides of these elements except those of nitrogen are stable.In case of nitrogen, only NF < sub > 3 < /sub> is known to be stable. Trihalides except BiF<sub>3</sub > are predominantly covalent in nature. < br > < br >
< li > Reaction with Metal < br >
All these elements react with metals to form their binary compounds exhibiting - 3 oxidation state, such as, Ca < sub > 3 < /sub>N<sub>2</sub > (Calcium nitride), Ca < sub > 3 < /sub>P<sub>2</sub > (Calcium phosphide), Na < sub > 3 < /sub>As<sub>2</sub > (Sodium arsenide), Zn < sub > 3 < /sub>Sb<sub>2</sub > (Zinc antimonide) and Mg < sub > 3 < /sub>Bi<sub>2</sub > (Magnesium bismuthide). < br > < br >
< /ul>");
}
else if (item === 4)
{
document.write("<b><h3>Chemical Reactions for GROUP 16 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
All the elements of Group 16 form hydrides of the type H < sub > 2 < /sub>E (E = S, Se, Te, Po). Their acidic character increases from H<sub>2</sub > O to H < sub > 2 < /sub>Te. The increse in acidic character can be explained in terms of decrease in bond (H-E) dissociation enthalpy down the group. Owing to the decrease in bond (H-E) dissociation enthalpy down the group, the thermal stability of hydrides also decreases from H<sub>2</sub > O to H < sub > 2 < /sub>Po. All the hydrides except water possess reducing property and this character increases from H<sub>2</sub > S to H < sub > 2 < /sub>Te.<br><br>
< li > Reaction with Oxygen < br >
All these elements form oxides of the EO < sub > 2 < /sub> and EO<sub>3</sub > types where E = S, Se, Te or Po.Ozone (O < sub > 3 < /sub>) and sulphur dioxide (SO<sub>2</sub > ) are gases while selenium dioxide (SeO < sub > 2 < /sub>) is solid. Reducing property of dioxide decreases from SO<sub>2</sub > to TeO < sub > 2 < /sub>. SO<sub>2</sub > is reducing while TeO < sub > 2 < /sub> is an oxidising agent. Besides EO<sub>2</sub > type, sulphur, selenium and tellurium also form EO < sub > 3 < /sub> type oxides (SO<sub>3</sub > , SeO < sub > 3 < /sub>, TeO<sub>3</sub > ).Both types of oxides are acidic in nature. < br > < br >
< li > Reaction with Halogen < br >
Elements of Group 16 form a large number of halides of the type, EX < sub > 6 < /sub>, EX<sub>4</sub > and EX < sub > 2 < /sub> where E is an element of the group and X is a halogen. The stability of the halides decreases in the order F<sup>-</sup > & gt; Cl < sup > - < /sup> > Br<sup>-</sup > & gt; I < sup > - < /sup>. Amongst hexahalides, hexafluorides are the only stable halides. All hexafluorides are in gaseous nature. They have octahedral structure. Sulphur hexafluoride, SF<sub>6</sub > is exceptionally stable for steric reasons. < br >
Amongst tetrafluorides, SF < sub > 4 < /sub> is a gas, SeF<sub>4</sub > a liquid and TeF < sub > 4 < /sub> a solid. These fluorides have sp<sup>3</sup > d hybridisation and thus, have trigonal bipyramidal structures in which one of the equatorial positions is occupied by a lone pair of electrons.This geometry is also regarded as see - saw geometry. < br >
All elements except selenium form dichlorides and dibromides.These dihalides are formed by sp < sup > 3 < /sup> hybridisation and thus, have tetrahedral structure. The well known monohalides are dimeric in nature. Examples are S<sub>2</sub > F < sub > 2 < /sub>, S<sub>2</sub > Cl < sub > 2 < /sub>, S<sub>2</sub > Br < sub > 2 < /sub>, Se<sub>2</sub > Cl < sub > 2 < /sub> and Se<sub>2</sub > Br < sub > 2 < /sub>. These dimeric halides undergo disproportionation as given below: <br><br>
2Se < sub > 2 < /sub>Cl<sub>2</sub > → SeCl < sub > 4 < /sub> + 3Se <br><br>
< /ul>");
}
else if (item === 5)
{
document.write("<li><b><h3>Chemical Reactions for GROUP 17 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
They all react with hydrogen to give hydrogen halides but affinity for hydrogen decreases from fluorine to iodine.They dissolve in water to form hydrohali acids.The acidic strength of these acids varies in the order: HF & lt; HCl & lt; HBr & lt; HI.The stability of these halides decreases down the group due to decrease in bond (H - X) dissociation enthalpy in the order: H - F & gt; H - Cl & gt; H - Br & gt; H - I. < br > < br >
< li > Reaction with Oxygen < br >
Halogens form many oxides with oxygen but most of them are unstable.Fluorine forms two oxides OF < sub > 2 < /sub>, O<sub>2</sub > F < sub > 2 < /sub>. However, only OF<sub>2</sub > is thermally stable at 298 K.These oxides are essentially oxygen fluorides because of the higher electronegativity of fluorine than oxygen.Both are strong fluorinating agents.O < sub > 2 < /sub>F<sub>2</sub > oxidises plutonium to PuF < sub > 6 < /sub> and the reaction is used in removing plutonium as PuF<sub>6</sub > from spent nuclear fuel. < br >
Chlorine, bromine and iodineChlorine, bromine and iodine form oxides in which the oxidation
states of these halogens range from + 1 to + 7. A combination of kinetic and thermodynamic factors lead to the generally decreasing order of stability of oxides formed by halogens, I & gt; Cl & gt; Br.The higher oxides of halogens tend to be more stable than the lower ones. < br >
Chlorine oxides, Cl < sub > 2 < /sub>O, ClO<sub>2</sub > , Cl < sub > 2 < /sub>O<sub>6</sub > and Cl < sub > 2 < /sub>O<sub>7</sub > are highly reactive oxidising agents and tend to explode.ClO < sub > 2 < /sub> is used as a bleaching agent for paper pulp and textiles and in water treatment.<br>
The bromine oxides, Br < sub > 2 < /sub>O, BrO<sub>2</sub > , BrO < sub > 3 < /sub> are the least stable halogen oxides (middle row anomally) and exist only at low temperatures. They are very powerful oxidising agents. The iodine oxides, I<sub>2</sub > O < sub > 4 < /sub>, I<sub>2</sub > O < sub > 5 < /sub>, I<sub>2</sub > O < sub > 7 < /sub> are insoluble solids and
decompose on heating.I < sub > 2 < /sub>O<sub>5</sub > is a very good oxidising agent and is
used in the estimation of carbon monoxide. < br > < br >
< li > Reaction with Metals < br >
Halogens react with metals to form metal halides.For example, bromine reacts with magnesium to give magnesium bromide. < br > < br >
Mg(s) + Br < sub > 2 < /sub>(l) → MgBr<sub>2</sub > (s) < br > < br >
The ionic character of the halides decreases in the order MF & gt;
MCl & gt; MBr & gt; MI where M is a monovalent metal.If a metal exhibits
more than one oxidation state, the halides in higher oxidation
state will be more covalent than the one in lower oxidation state.
For example, SnCl < sub > 4 < /sub>, PbCl<sub>4</sub >
, SbCl < sub > 5 < /sub> and UF<sub>6</sub >
are more covalent than SnCl < sub > 2 < /sub>
, PbCl < sub > 2 < /sub>, SbCl<sub>3</sub >
and UF < sub > 4 < /sub> respectively.<br><br>
< li > Reaction with Halogens < br >
Halogens combine amongst themselves to form number of compounds known as interhalogens of the types XX < sup > ` < /sup>, XX<sup>`</sup > < sub > 3 < /sub>, XX<sup></sup > < sub > 5 < /sub> and XX<sup>`</sup > < sub > 7 < /sub> where X is a larger size halogen and X<sup>`</sup > is a smaller size halogen. < br > For example: & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; I < sub > 2 < /sub> + Cl<sub>2</sub > & nbsp; → 2ICl < br > & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; (equimolar) < br > < br >
< /ul>");
}
}
</script>
</body>
</html>
Pastebin code
Problems I had to fix;
< br > turns in to plain text: < br > . Use this instead for ALL the HTML tags: <br> without the spaces.
if (item === 2) ???? Item was not defined, had to change it to if (g === "2") ; Please note that "2" is not the same as 2
Applied a classname group to every div; to Hide them whenever the gr() is called.
Goodluck, Jeroen
The problem is in the document.write
You can't do: document.write("")
The javascript thinks website.html is a variable
In your code:
document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br>
< ul type = "disc" >
It expects "disc" to be a variable
You either can encode all of the " symbols, or put the text in divs and show them when you select an option.
Also; with document.write you can't use [enter] to prettify your code.
Your best bet is placing the text in separate divs and showing/hiding them whenever you hit the see button !
Jeroen

date.day() returns TypeError: 'int' object is not callable

I'm stuck. It appears that day is being overwritten as an int somewhere. But where? Where is day becoming an int?
from datetime import *
start_date = date(1901, 1, 1)
end_date = date(2000, 12, 31)
sundays_on_1st = 0
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
for single_date in daterange(start_date, end_date):
# type(single_date) => <type 'datetime.date'>
# type(date.day()) => TypeError: 'getset_descriptor' object is not callable
# type(single_date.day()) => TypeError: 'int' object is not callable
# ಠ_ಠ
if single_date.day() == 1 and single_date.weekday() == 6:
sundays_on_1st += 1
print sundays_on_1st
.day is not a method, you do not need to call it. Only .weekday() is a method.
if single_date.day == 1 and single_date.weekday() == 6:
sundays_on_1st += 1
This works just fine:
>>> for single_date in daterange(start_date, end_date):
... if single_date.day == 1 and single_date.weekday() == 6:
... sundays_on_1st += 1
...
>>> print sundays_on_1st
171
>>> type(single_date.day)
<type 'int'>
From the datetime.date documentation:
Instance attributes (read-only):
date.year
Between MINYEAR and MAXYEAR inclusive.
date.month
Between 1 and 12 inclusive.
date.day
Between 1 and the number of days in the given month of the given year.
It is implemented as a data descriptor (like a property) to make it read-only, hence the TypeError: 'getset_descriptor' object is not callable error you saw.