Sanjana - FOP Assignment 1
Sanjana - FOP Assignment 1
1) Arithmetic operators
CODE :
n1 = int (input("Enter tne first number: "))
n2 = int (input("Enter tne second number: "))
ans = n1 + n2
print("sum =",ans)
ans = n1 - n2
print("sub =",ans)
ans = n1 * n2
print("mul =",ans)
ans = n1 / n2
print("div =",ans)
ans = n1 % n2
print("mod =",ans)
ans = n1 ** n2
print("expo =",ans)
ans = n1 // n2
print("floor div =",ans)
OUTPUT :
2) Assignment operators
CODE :
x=5#=
print(x)
x = 5 # +=
x += 3
print(x)
x = 5 # -=
x -= 3
print(x)
x = 5 # *=
x *= 3
print(x)
x = 5 # /=
x /= 3
print(x)
x = 5 # %=
x%=3
print(x)
x = 5 # //=
x//=3
print(x)
x = 5 # **=
x **= 3
print(x)
x = 5 # &=
x &= 3
print(x)
OUTPUT :
3) Comparison operators
CODE :
# Comparision operators
x=5
y=3
print(x == y)
x=5
y=3
print(x != y)
x=5
y=3
print(x > y)
y=3
print(x > y)
x=5
y=3
print(x >= y)
x=5
y=3
print(x <= y)
OUTPUT:
4) Logical operators
CODE :
x=5
x=5
OUTPUT:
CODE : 1) is/not is
x = ["Sanjana"]
z = ["Sanjana"]
OUTPUT:
2) in/not in
CODE:
my_list = ["FOP","MM","ITTS"]
OUTPUT:
6) Bitwise operators
CODE :
# Bitwise AND
result_and = a & b
result_or = a | b
# Bitwise XOR
result_xor = a ^ b
# Bitwise NOT
c = 10 # 1010 in binary
result_not = ~c
# Left Shift
result_left_shift = d << 2
# Right Shift
e = 16 # 10000 in binary
result_right_shift = e >> 2
OUTPUT:
6. Write a note on conditional statements and their advantages.Explain if-elif with example
(Find minimum number among given 3 numbers)
ANS Conditional statements (if, else, and elif) are fundamental programming
constructs that allow you to control the flow of your program based on conditions
that you specify.
Advantages of conditional statements :-
1. Control Flow: Direct how your program behaves based on conditions.
2. Decision Making: Choose actions based on evaluations.
3. Flexibility: Handle diverse scenarios and changing data.
4. Modularity: Organize code into manageable blocks.
5. Error Handling: Implement error prevention and handling.
6. User Interaction: Respond to user input dynamically.
7. Dynamic Behavior: Adapt behavior as conditions change.
8. Readability: Enhance code clarity for others and yourself.
9. Efficiency: Optimize code execution based on conditions.
10. Logic Implementation: Implement complex logical operations.
CODE :
n1 = 1
n2 = 23
n3 = 11
if (n1<n2) and (n1<n3):
print (n1,"is smallest number")
elif (n2<n3):
print (n2,"is smallest number")
else:
print (n3,"is smallest number")
OUTPUT :
7. What is string? Describe any 5 string functions with example.
ANS String is sequence of character .
Examples
1) Escape sequence
2) is alpa or numeric
3) Translate function
4) split function
5) Find function
9. Write a python script to input two names and check whether both are equal or not.
CODE :
name = input('Enter your name :')
def compare(a, b):
if a == b:
return True
return False
result = compare(x, y)
if result == True:
print("Two numbers are equal")
else:
print("Two numbers are not equal")
OUTPUT:
OUTPUT: