-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial4_python_operators.py
More file actions
106 lines (85 loc) · 2.35 KB
/
tutorial4_python_operators.py
File metadata and controls
106 lines (85 loc) · 2.35 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# ============================================
# Tutorial 4 - Python Operators
# ============================================
# --------------------------------------------
# Python Operators
# --------------------------------------------
# * Logical
# * Equality
# * Comparison
# * Arithmetic
# ============================================
# 4.1.1 Logical Operators
# ============================================
# In python, the following keywords are used for boolean operations:
# not - unary negation
# and - conditional AND
# or - conditional OR
# --------------------------------------------
# Examples:
# --------------------------------------------
print(type(False)) # bool
print(bool(1)) # True
a = True
b = False
print(True and False) # False
print(True or False) # True
print(not False) # True
age = int(input("Enter the age: "))
if age < 18 or age >= 35:
print("Successful execution")
# ============================================
# Equality Operators
# ============================================
# Operators:
# is -> a is b (same object)
# is not -> a is not b (different objects)
# == -> a == b (same value)
# != -> a != b (different values)
a = "Rupesh"
b = "Rupesh1"
print(a == b) # False
age = int(input("Enter the age: "))
if age == 18:
print("You are in the teenager age")
a = "Rupesh"
b = "Rupesh"
print(id(a))
print(id(b))
print(a is b) # True
lst = [1, 2, 3]
lst1 = [1, 2, 3]
print(id(lst))
print(id(lst1))
print(lst is lst1) # False
print(lst is not lst1) # True
print("Rupesh" != "Rupesh1") # True
# ============================================
# Comparison Operators
# ============================================
# < less than
# <= less than or equal to
# > greater than
# >= greater than or equal to
marks = float(input("Enter the marks: "))
if marks >= 35:
print("Pass")
if marks >= 50 and marks <= 70:
print("First")
elif marks < 35:
print("Fail")
# ============================================
# Arithmetic Operators
# ============================================
# + addition
# - subtraction
# * multiplication
# / true division
# // integer division
# % modulo
print(24 + 24) # 48
print(48 - 24) # 24
print(48 * 24) # 1152
print(48 / 4) # 12.0
print(48 // 5) # 9
print(48 % 5) # 3