"""
Code-03.py
Author: M. Reza Mozaffari
Physics Group, University of Qom
created on: Mar. 2021
"""
# Relational Operators:
# equal to: ==
# not equal to: !=
# less than: <
# greater than: >
# leas than or equal to: <=
# greater than or equal to: >=
x = 2.25
print(x > 3.50)
y = x > 3.50
print("y = ", y)
print(type(y))
x = 25
y = 25.0000000000000
print(x == y)
print(id(x))
print(id(y))
x = "Reza"
y = "reza"
print(x == y)
print(x != y)
# Chain
x = -0.75
y = 0.25 < x <= 1.0
print("y = ", y)
# Mermbership and Identity Operators:
# Membership Operator: in/ not in
# Identity Operator: is/ is not (so similar equat to operator ==/!=)
x = "Numerical Calculations!"
print("x = ", x)
y = "meri" in x
print(y)
print("Meri" in x)
print("Meri" not in x)
x = 25
y = 25.0000000000000
print(x == y)
print(id(x) == id(y))
print(x is y)
print(x is not y)
x = 5
y = x
print(x == y)
print(id(x) == id(y))
print(x is y)
print(x is not y)
# logical Operators:
# not
# and
# or
# not
x = True
print("x = ", x)
print(not x)
print(3.5 <= 10.0)
print(not 3.5 <= 10.0)
# and
# T: True, F: False
# T and T = T
# F and T = F
# T and F = F
# F and F = F
# or
# T or T = T
# F or T = T
# T or F = T
# F or F = F
x = 0.75
# chain
y = 0.25 < x < 1.0
# logical
z = x > 0.25 and x < 1.0
print(y == z)
# ------------\\\\\\\\\\\\----------
# 0.25 1.0
x = 0.5
y = x <= 0.25 or x >= 1.0
print("y = ", y)
x = 3 > 2
z = not x and 3.5 <= 5.0 or 2 <-1
print("z = ", z)
print(False and True or False)
print(False and (True or False))
print((False and True) or False)
w = False or True and False and True
print("w = ", w)
print(False or True and False and True)
print((False or True) and (False and True))
print((False or (True and (False and True))))
print(False or (True and False) and True)
# Conditional Statements: if
# if condtion:
# body of if condition
x = "Numerical Calculations!"
y = "Meri"
print(y in x)
if y in x:
print("Yes, ", y, " is in ", x)
if y not in x:
print("No, ", y, " is not in ", x)
# if condtion:
# body of if condition
# else:
# body of else
if y in x:
print("Yes, ", y, " is in ", x)
else:
print("No, ", y, " is not in ", x)
x = 16
if x % 2 == 0:
print(x, "is even!")
else:
print(x, "is odd!")
# if condtion1:
# body of if condition1
# elif condition2:
# body of if condition2
# else:
# body of else
# ------------\\\\\\\\\\\\----------
# bad 0.25 good 1.0 well
y = 2.8
if y < 0.25:
print("The bad state!")
elif y>=0.25 and y <=1.0:
print("The good state!")
else:
print("The well state!")
# if condtion:
# if nestedcindition:
# body if nestedcindition
# .
# .
# .
# else:
# body of else
# [0, 20]
score = 21.0
if score >= 0.0 and score <= 20.0:
if score >= 19.0 and score <= 20.0:
print("The grade is Excellent.")
elif score >= 18.0 and score <= 19.0:
print("The grade is Very Good.")
elif score >= 16.0 and score <= 18.0:
print("The grade is Good.")
elif score >= 12.0 and score <= 16.0:
print("The grade is Acceptable.")
elif score >= 10.0 and score <= 12.0:
print("The grade is Poor.")
else:
print("The grade is Fail.")
else:
print("The score is not in range, [0, 20]!")