## Search This Blog

### various operation on string using string libraries with algorithm

Q) : Implement python script to perform various operation on string using string libraries

Aim : To perform variable operation on string using string libraries

Algorithm :

step 1: Start
step 2: initialise upper case letters
capotal = str.upper()
step 3: Initialise upper case letter
small = capital.lower()
step 4: Replace str1 to str2
str2 = str1.replace("students',"engineer")
step 5: print left and right strips
left  = str1.strip()
right = str1.strip()
step 6: print prefixes
prefix1 = str1.startwith("wel come")
step 7: end

Source Code:
```str1 = "wel come to all student"capital = str1.upper()
print(capital)
str2 = "WEL COME TO MITS"lower = str2.lower()
print(str2)
print(str3)
str4 = "This is an example of strip"left = str4.strip()
print(left)
prefix1 = str1.startswith('hellow')
print(prefix1)
prefix2 = str1.startswith('wel')
print(prefix2)
prefix3 = str1.endswith('student')
print(prefix3)

Output:```
```
```
```WEL COME TO ALL STUDENT
WEL COME TO MITS
This is an example of strip
False
True
True

Process finished with exit code 0
```

## Q) : Implement python script to print factorial of number .

Aim: To print factorial number

Algorithm:

step 1; Start
step 2; Declare the variable n and read n value
step 3: Initialise fact = 1 and i = 1
step 4: In while loop perform
fact = fact * i
i = i + 1
step 5: print factorial of n
step 6: end

Source Code:

```n = int(input('enter the number :'))
fact1 = 1```
```
```
`i = 1`
```while n >= i:
fact2 = fact1 * i
i = i + 1```
`    print(f"factorial number of n is {fact2}")`
```
```
`Input:`
`enter the number: 50`
```
```
`Outout:`
```
```
```enter the number :50
factorial number of n is 1
factorial number of n is 2
factorial number of n is 3
factorial number of n is 4
factorial number of n is 5
factorial number of n is 6
factorial number of n is 7
factorial number of n is 8
factorial number of n is 9
factorial number of n is 10
factorial number of n is 11
factorial number of n is 12
factorial number of n is 13
factorial number of n is 14
factorial number of n is 15
factorial number of n is 16
factorial number of n is 17
factorial number of n is 18
factorial number of n is 19
factorial number of n is 20
factorial number of n is 21
factorial number of n is 22
factorial number of n is 23
factorial number of n is 24
factorial number of n is 25
factorial number of n is 26
factorial number of n is 27
factorial number of n is 28
factorial number of n is 29
factorial number of n is 30
factorial number of n is 31
factorial number of n is 32
factorial number of n is 33
factorial number of n is 34
factorial number of n is 35
factorial number of n is 36
factorial number of n is 37
factorial number of n is 38
factorial number of n is 39
factorial number of n is 40
factorial number of n is 41
factorial number of n is 42
factorial number of n is 43
factorial number of n is 44
factorial number of n is 45
factorial number of n is 46
factorial number of n is 47
factorial number of n is 48
factorial number of n is 49
factorial number of n is 50

Process finished with exit code 0
```

## Q) : Implement python script to check given number is palindrome or not .

Aim: To check given number is palindrome or not

Algorithm :
step 1: Start
step 2: Declare the variable n and read n
step 3: Assign n = k
step 4: Initialise r = 0
step 5: In while loop  perform
d = n % 10
r = r * 10 + d
n = math . floor(n / 10)
step 6: check the condition r == k
step 7: If the condition is true print that given number is palindrome
step 8: Otherwise print the given number is not palindrome
step 9: end

Source Code:

```import math
n = int(input('enter the number :'))
k = n
r = 0 ```
```while n > 0:
d =n % 10  ```
```    r = r * 10 + d
n = math.floor(n/10)
if r == k:
print('given number is palindrom ')
else:
print('given number is not palindrome')
```
```
```
`input:`
```
```
`enter the number:1212`
```
```
`Output :`
```enter the number :1212
given number is not palindrome

Process finished with exit code 0
```
```
```
```input:

enter the number:212
```
`OutPut:`
enter the number :212
given number is  palindrome

Process finished with exit code 0

## Q):Implement python script to generate prime number series up to n

Aim: To generate prime number series up to n
Algorithm:
step 1: Start
step2: Declare lower variable and read
step 3: Declare higher variable and read.
step 4: In n for loop take the range of value from lower to higher .
step 5 : Check for the condition n > 1
step 6: If the condition is true go to the i for loop otherwise take the next iteration
step 7: In i for loop check the condition n % i = 0
step 8: if the condition is true then break the loop otherwise print that n value
step 9: end.

Source code:

lower = int(input("enter lower range:"))
```higher = int(input("enter higher range:"))
for num in range(lower,higher + 1):
# prime numbers are greater than 1 ```
```  if num > 1:
for i in range(2,num):
if (num % i) == 0:
break     ```
```        else:
print(num)```
```
```
```
```
`Output:`
```enter lower range:0
enter higher range:50
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

Process finished with exit code 0
```