You are on page 1of 4

In 

[14]: lists=['ariana','nicki','taylor','doja']
print("ariana" in lists)

Trần Tuấn Anh-11219259-DSEB63 print("cardi" in lists)

True
False

In [21]: alien_color='green','yellow','red'
if "green" in alien_color:
print("you got 5 points")
else:
print("You got no points")

you got 5 points


In [2]: test="ariana"
print(test=="ariana")
print(test!="ariana")

True
False

In [4]: test="nicki"
print(test.lower()=="nicki")

True

In [6]: test="10"
print(test=="10")
print(test>="10")
print(test<="10")
print(test!="10")
print(test>"10") In [20]: alien_color='green','yellow','red'
print(test<"10") if "green" in alien_color:
print("You got 5 points for shooting the alien")
True else:
True print("You got 10 points")
True
False You got 5 points for shooting the alien
False
False

In [11]: test="3"
print(test=="3")
print(test!="3")
if test>"2" and test<"4":
print()
if test<"2" or test<"4":
print()

True
False

In [22]: alien_color='green','yellow','red'
if 'green' in alien_color:
print("You got 5 points") else:
elif 'yellow' in alien_color: print("I don't like grape")
print("You got 10 points") if 'watermelon' in favorite_fruit:
elif 'red' in alien_color: print("I really like watermelon")
print("You got 15 points") if 'apple' in favorite_fruit:
print("I like apple")
You got 5 points if 'mango' in favorite_fruit:
print("I like mango")
else:
print("I don't like mango")

I really like coconut


I don't like grape
I really like watermelon
I like apple
I don't like mango

In [40]: aTuple = ("Orange", [10, 20, 30], (5, 15, 25))


print(aTuple[1][1])

20

In [29]: age=3 In [51]: empty_tuples=[(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
if age<2: del empty_tuples[0]
print("You are a baby") del empty_tuples[0]
elif age<4 and age>=2: print(empty_tuples)
print("You are a toddler")
elif age<13: [('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
print("You are a kid")
elif age<20: In [56]: tuple1 = (11, [22, 33], 44, 55)
print("You are a teenager") #tuple[0]=11
elif age<65: #tuple[1][0]=22 tuple[1][1]=33
print("You are an adult") #tuple[2]=44
else: #tuple[3]=55
print("You are an elder")
tuple1[1][0]="222"
You are a toddler print(tuple1)

(11, ['222', 33], 44, 55)

In [37]: favorite_fruit=['coconut','apple','watermelon']
if 'coconut' in favorite_fruit:
print("I really like coconut")
if 'grapes' in favorite_fruit: In [60]: sampleSet = {"Yellow", "Orange", "Black"}
print("I like grape") sampleList = ["Blue", "Green", "Red"]
sampleSet.update(sampleList)
print(sampleSet)

{'Black', 'Orange', 'Yellow', 'Green', 'Blue', 'Red'}

In [108… set1={10,20,30,40,50}
list1=list(set1)
list1.sort()
#xóa phần tử đầu tiên 3 lần(list1[0]) nên i trong khoảng từ 1 đến 4
for i in range(1,4):
del list1[0]
set1=set(list1)
print(set1)

{40, 50}

In [126… set1 = {10, 20, 30, 40, 50}


set2 = {30, 40, 50, 60, 70} In [1]: message = """Machine learning; (ML) is the study of \computer algorithms that impro
set3=set1.intersection(set2) special_chars = {'.', ',', "\\", ';', '-', '(', ')', '{', '}', '#', '*', '"', '?',
print(set3) message = message.lower()
set4=set1.union(set2) for chars in special_chars:
print(set4) message = message.replace(chars, ' ')
set1.difference_update(set2) message = message.replace(' ', ' ')
print(set1) message = message.replace('\n', '')
print(len(message.split(' ')), 'words.')
{40, 50, 30}
{70, 40, 10, 50, 20, 60, 30} 149 words.
{20, 10}
In [3]: print(len(set(message.split(' '))), 'different words.')
In [125… set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70} 91 different words.

print(set1.symmetric_difference(set2)) In [4]: unique = set(message.split(' '))


count = []
{20, 70, 10, 60} for words in sorted(unique):
count.append([words,message.split(' ').count(words)])
print(count)
[['', 1], ['a', 4], ['across', 1], ['algorithms', 4], ['also', 1], ['analysis',
1], ['analytics', 1], ['and', 2], ['application', 2], ['applications', 1], ['are',
1], ['artificial', 1], ['as', 4], ['automatically', 1], ['based', 1], ['being',
1], ['build', 1], ['business', 1], ['closely', 1], ['computational', 1], ['compute
r', 2], ['computers', 1], ['conventional', 1], ['data', 4], ['decisions', 1], ['de
livers', 1], ['develop', 1], ['difficult', 1], ['do', 1], ['domains', 1], ['emai
l', 1], ['experience', 1], ['explicitly', 1], ['exploratory', 1], ['field', 2],
['filtering', 1], ['focuses', 1], ['focusing', 1], ['improve', 1], ['in', 3], ['in
feasible', 1], ['intelligence', 1], ['is', 6], ['it', 2], ['its', 1], ['known',
1], ['learning', 7], ['machine', 6], ['make', 1], ['making', 1], ['mathematical',
2], ['methods', 1], ['mining', 1], ['ml', 1], ['model', 1], ['needed', 1], ['of',
6], ['on', 3], ['optimization', 1], ['or', 2], ['order', 1], ['perform', 1], ['pre
dictions', 2], ['predictive', 1], ['problems', 1], ['programmed', 1], ['referred',
1], ['related', 2], ['sample', 1], ['seen', 1], ['so', 1], ['statistics', 1], ['st
udy', 3], ['subset', 1], ['such', 1], ['tasks', 1], ['that', 1], ['the', 4], ['the
ory', 1], ['through', 2], ['to', 7], ['training', 1], ['unsupervised', 1], ['use
d', 1], ['using', 1], ['variety', 1], ['vision', 1], ['where', 1], ['which', 1],
['wide', 1], ['without', 1]]

In [ ]:

In [13]: B = 'A(x,y)=2xy+4x+5y+x^2-y^2-5'
B=B.split("=")
print(B)
B[1]=B[1].replace("-","+-")
print(B[1])
B[1]=B[1].split("+")
print(B[1])
print("The variables is ",B[1])
x=float(input("x="))
y=float(input("y="))
A=2*x*y+4*x+5*y+x**2-y**2-5
print("A(x,y)=",A)

['A(x,y)', '2xy+4x+5y+x^2-y^2-5']
2xy+4x+5y+x^2+-y^2+-5
['2xy', '4x', '5y', 'x^2', '-y^2', '-5']
The variables is ['2xy', '4x', '5y', 'x^2', '-y^2', '-5']
x=2
y=3
A(x,y)= 25.0

In [ ]:

You might also like