Professional Documents
Culture Documents
[14]: lists=['ariana','nicki','taylor','doja']
print("ariana" 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")
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")
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)
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)
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 [ ]:
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 [ ]: