forked from inspirezonetech/TeachMePythonLikeIm5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparison.py
50 lines (40 loc) · 2.15 KB
/
comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ------------------------------------------------------------------------------------
# Comparision Operators in Python
# ------------------------------------------------------------------------------------
# So basically there are 6 Comparison Operators in Python , let us learn them one by one .
# Note : One more thing to note is that whenever you compare two "things" , the return value of this Comparision will be either True or False
# 1. "=="(Equal) -> we use this operator to see if two variables are equal.
a = 5
b = 5
print(a == b) # Here since a and b are equal we will get True in output.
# 2. "!="(Not Equal) -> we use this operator to see if two variables are equal or not , if they are not equal it will return True else False.
a = 5
b = 5
print(a != b) # Here since a and b are equal we will get False in output.
# 3. ">"(Greater than ) -> we use this operator to see if one variable is greater than other.
a = 9
b = 5
print(a > b) # Here since a is greater than b , we will get True in output.
# 4. ">="(Greater than or equal to ) -> we use this operator to see if two variables are equal or one is grater than the other.
a = 5
b = 5
print(a >= b) # Here since a and b are equal, we will get True in output.
# 5. "<"(Less than ) -> we use this operator to see if one variable is less than other.
a = 9
b = 5
print(a < b) # Here since a is greater than b , we will get False in output.
# 6. "<="(Less than or equal to ) -> we use this operator to see if two variables are equal or one is less than the other.
a = 3
b = 5
print(a <= b) # Here since a is less than b , we will get True in output.
# ------------------------------------------------------------------------------------
# Challenge for you :
# ------------------------------------------------------------------------------------
# Given a array of numbers .
# Traverse the array and print following :
# If the number is less than 10 - print "The number is smaller than 10."
# If the number is greater than 10 - print "The number is greater than 10."
# If the number is equal t0 10 - print "The number is equal to 10."
# The array nums is given below .
nums = [1, 3, 10, -7, 8]
# write your code here