Type-Based Programming Topic! (Official)

coding
othercodinglanguages
official
luna_was_here
opentopicforeveryone

#187

Yes, I know how to! What do you want to know more specifically?


#188

I want to know how to access exactly one item in the dictionary.


#189

Oh, you just use .get() and then input the dictionary name in the parentheses. So, if you had this dictionary:
{"car": "BMW", "color": "Green"}
and want to get the value “color” and then print it, you should do like this:

carinfo = {
"car": "BMW", 
"color": "Green"
}
print(carinfo.get("color"))

Python console output:
Green

I also couldn´t figure this out at first, but when I found out that dicts were this easy to use, I have used them a lot for storing information in files, and dicts are pretty much the same as JSONs, except that dicts are used for storing information in your programs, but not doing things like saving information to files. You have to convert them to JSON in order to do that.

But now that you have learned this, you should really try to learn how to use APIs with Python! There are lots of guides online how to do that.


#190

Thanks! Is because I want to do some projects with libraries, plus I want to change my iPad Cypher code so that it all goes to a lbrary, like Lisp said.
(I wished this topic was more alive :sweat_smile:)


#191

Me too. Programming is so interesting.


#192

Yes agree I’ve used c# as well


#193

It’s just different bases, binary is base 2, hexadecimal is base 16, octogonal I would think it was base 8. Hexadecimal goes like this:
1 2 3 4 5 6 7 8 a b c d e f g h
(H is 16)
Binary is just
0 1
And octagonal would be
1 2 3 4 5 6 7 8
And when you get to 16 in hexadecimal, it would be 10, or 16 plus 0.


#194

Okay, thank you!
(At least I get activity in this topic that isn’t me asking questions XD)


#195

Lol no problem just helping because why not


#196

It’s actually known as “octal.”
“Octagonal” refers to having eight sides.
The set of digits in octal is not as mentioned, but rather:
0,1,2,3,4,5,6,7.

A more interesting base however is unary.
In unary there is only one symbol, and the quantity of a number is determined by the amount of symbols.
Example:

“11” - 2 in base 10.
“1111111” - 7 in base 10.
" " - 0 in base 10.


#197

Ah ok that makes sense


#198

additionally, hexadecimal has the following characters:
0 1 2 3 4 5 6 7 8 9 a b c d e f
as opposed to the stated ones.

counting to 20 in a few systems:

base 10 base 2 base 16 base 8
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 8 10
9 1001 9 11
10 1010 a 12
11 1011 b 13
12 1100 c 14
13 1110 d 15
14 1111 e 16
15 10000 f 17
16 10001 10 20
17 10010 11 21
18 10011 12 22
19 10100 13 23
20 10101 14 24

what each place value is (corresponding to base 10):

dec hex bin oct
1 1 1 1
10 16 2 8
100 256 4 64
1000 2048 16 256

Each place is multiplied by the base number
(might need to be checked, did off the top of my head)
not very hard to understand, just kind of confusing to remember