a = input("enter the value a")
b = input("enter the value b")
print(a + b) # it will concatenate the value as it is taking string value
a = int(input("enter the value a"))
b = int(input("enter the value b"))
print(a + b)
a = eval(input("enter the value a")) # converts binary as well in an integer value
b = eval(input("enter the value b"))
print(a + b)
a = int(input("enter the value a"))
if a%2==0:
print (a, "is an even number.") #indentation is must in if condition, level of the statements should be the same
else:
print(a, "is an odd number.")
per=int(input("enter the value"))
if per>= 60:
print("First Div")
elif per>=45:
print("Second Div")
elif per>= 30:
print("Pass")
else:
print("Fail")
a = int(input("Enter the value to calculate"))
b = int(input("enter the value to calculate"))
cal = input("add: +,sub: -, div: /,mul: * ")
if cal == "+":
print(a + b)
elif cal == "-":
print(a - b)
elif cal == "/":
print(a / b)
elif cal == "*":
print(a * b)
else:
print("invalid input")
Range: range(5) start with 0 and condition less than the range value (0,1,2,3,4) range (1,6) start with 1(1,2,3,4,5) 1 less than the end range value range (1,6,2): start with 1, end 1 less than 6 (2nd value), and increment with 2, that is: - 1,3,5
for n in range(5):
print(n)
for n in range(2,6):
print(n)
for n in range(2,22,2):
print(n)
for a in range(1,11):
print("2 x",a,"= ")
for n in range(10,0,-1):
print(n)
i = 1
while i <= 10:
print(i, "loop")
i = i + 1
print(i) # 10 times it will repeat but the last value will be 11.
String slicing
w = "String Index"
print(w[7]) # it will give the value which is present in index 7
print(w[0:7]) # it will print till index 1-7 that is 6 , it is called slicing
print(w[0::2]) # here 2 is the increment vale of the index which
print(w[-1::-1]) # it will print reverse string value till last
print(w[-1:-7:-1]) # it will reverse till -6 1 less than -7 and will increment by -1