In [1]:
1 + 1
Out[1]:
In [2]:
12 * 44
Out[2]:
In [3]:
Hello Data Skills!
In [4]:
'Hello Data Skills!'
Out[4]:
In [6]:
print 'Hello Data Skills!'
In [8]:
print "Hello Data Skills!"
print 'Hello Data Skills!'
print """Hello Data Skills!"""
In [10]:
type(1)
Out[10]:
In [11]:
type(1 + 1)
Out[11]:
In [21]:
type("hello")
Out[21]:
In [13]:
1 == 2
Out[13]:
In [14]:
1 == 1
Out[14]:
In [15]:
type(1 == 1)
Out[15]:
In [16]:
True
Out[16]:
In [17]:
False
Out[17]:
In [18]:
type(True)
Out[18]:
In [20]:
12 + 12 + "hello"
In [22]:
str(1)
Out[22]:
In [23]:
type(str(1))
Out[23]:
In [42]:
type(3.14)
Out[42]:
In [71]:
3 / 2
Out[71]:
In [72]:
3 / 2.0
Out[72]:
In [25]:
x = 1
In [26]:
print x
In [27]:
y = x + 2
In [28]:
print y
In [29]:
z = "hello"
In [30]:
z
Out[30]:
In [31]:
w = "python"
In [32]:
print z + w
In [33]:
print z + " " + w
In [34]:
x
Out[34]:
In [35]:
x = x + 1
In [36]:
print x
In [41]:
type(x)
Out[41]:
In [44]:
i = 10
print i % 2
In [45]:
i = 9
print i % 2
In [119]:
if i % 2 == 0:
print "even"
In [48]:
if i % 2 == 0:
print "even"
else:
print "odd"
In [49]:
i = 10
In [51]:
# execute "if" the code above with the new value
In [87]:
v = 1
In [88]:
if v < 10:
print "it's small"
else:
print "it's big"
In [52]:
def printeven(num):
if num % 2 == 0:
print "even"
else:
print "false"
In [53]:
printeven(10)
In [54]:
printeven(9)
In [56]:
printeven(i)
In [68]:
def printhuf(usd):
print "$" + str(usd) + " is " + str(272.9 * usd) + " Ft"
In [69]:
printhuf(10)
In [75]:
def printusd(huf):
print str(huf) + " Ft" + " is $" + str(huf / 272.9)
In [76]:
printusd(1000)
In [96]:
def printconvert(amount, currency):
if currency == "usd":
printhuf(amount)
else:
printusd(amount)
In [93]:
printconvert(10, "usd")
In [80]:
def tohuf(usd):
return 272.9 * usd
In [81]:
tohuf(10)
Out[81]:
In [153]:
x = printhuf(10)
In [154]:
print x
In [155]:
x is None
Out[155]:
In [156]:
isnone = x is None
In [157]:
print isnone
In [84]:
y = tohuf(10)
In [85]:
print y
In [99]:
# solution
def tousd(huf):
return huf / 272.9
def convert(amount, currency):
if currency == "usd":
return tohuf(amount)
else:
return tousd(amount)
print convert(10,"usd")
In [104]:
l = [2,4,6]
In [121]:
type(l)
Out[121]:
In [101]:
print l[0]
print l[2]
In [102]:
print l[3]
In [105]:
l.append(8)
In [106]:
print l
In [107]:
l[3]
Out[107]:
In [108]:
for elem in l:
print elem
In [112]:
range(1,10)
Out[112]:
In [113]:
range(1,11)
Out[113]:
In [114]:
tenelements = range(1,11)
In [115]:
for e in tenelements:
print e
In [118]:
for e in tenelements:
print tohuf(e)
In [122]:
# solution
for e in range(1,11):
if e % 2 == 0:
print e
In [123]:
def even(num):
return num % 2 == 0
In [124]:
for e in range(1,11):
if even(e):
print e
In [127]:
u = {
"username": "lili",
"password": "1982"
}
In [128]:
u["username"]
Out[128]:
In [129]:
u["password"]
Out[129]:
In [130]:
print u
In [137]:
import json
In [142]:
with open("passwords.json") as f:
d = json.load(f)
In [143]:
d
Out[143]:
In [145]:
type(d)
Out[145]:
In [146]:
d[2]
Out[146]:
In [148]:
for u in d:
print u
In [149]:
for u in d:
print u["username"]
In [161]:
# Solution
def printifinfile(username):
with open("passwords.json") as f:
j = json.load(f)
for record in j:
if record["username"] == username:
print "user found!!"
In [162]:
printifinfile("lili")
In [163]:
printifinfile("newuser")
In [ ]: