-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLec - 10 Comparison and Logical Operators.py
68 lines (49 loc) · 1.59 KB
/
Lec - 10 Comparison and Logical Operators.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Taking Input in Python
name = input()
print(name)
name = input('Enter your Name: ') # Provide a prompt to user
print(name)
# Data Type Conversion
# Example
a = input() # Suppose 5
b = input() # Suppose 10
print(a+b) # Then output will be 510 not 15 as these are string inputs
# String to int
a = int(a)
b = int(b)
print(a+b) # 15 this time
# Convert input directly to int
num = int(input())
print(type(num))
# Comparison Operators
# is equal to (==)
print(5 == 5) # True
print('rhythm' == 'rhythm') # True
print('rhythm' == 'Rhythm') # False as it is case - sensitive
password = input('Enter your password: ')
print(password == '123abc') # True if password matches 123abc
print(10.0 == 10) # True - float and int can be compared
# not equals to (!=)
print(10 != 10) # False
print(10 != 11) # True
# Greater than and less than
per = float(input('Enter Percentage: '))
print(per > 90) # True if percentage is greater than 90
print(per < 90) # True if percentage is less than 90
print(per >= 90) # True if percentage is greater than or equals 90
print(per <= 90) # True if percentage is less than or equals 90
# Chaining Operators
print(1 < 2 < 3) # True
# Logical Operators
# and - both conditions should be correct
print(1 < 2 and 2 < 3) # True
print(1 < 2 and 2 > 3) # False
username = input('Enter Username: ')
password = input('Enter Password: ')
print(username == 'rhythm' and password == '123')
# or - any of 2 conditions should be true
print(1 < 2 or 2 > 3) # True as 1 < 2
print(1 > 2 or 2 > 3) # False as both are false
# not - true -> false and false -> true
print(1 < 2) # True
print(not 1 < 2) # False