-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.py
More file actions
57 lines (51 loc) · 1.87 KB
/
class.py
File metadata and controls
57 lines (51 loc) · 1.87 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
#Assignment based on string operators
#1) wap to concatenation 2 string from userd input and print result on screen
def concatenate_strings():
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
result = str1 + " " + str2
print("Concatenated string:", result)
#2) wap to print substring form given string using slice operation
def substring_slice():
str1=input("Enter a string:")
start=int(input("Enter starting index:"))
end=int(input("Enter ending index:"))
substring=str1[start:end+1]
print("Substring:",substring)
#3) wap to declare 3 string using 3 different ways and multiply each string by 2 and print result on screen
def string_multiplication():
str1 = "Hello"
str2 = 'World'
str3 = """Python"""
print(f'String 1: "{str1}"')
print(f"String 2: '{str2}'")
print(f'String 3: """{str3}"""')
result1 = str1 * 2
result2 = str2 * 2
result3 = str3 * 2
print("String 1 multiplied by 2:", result1)
print("String 2 multiplied by 2:", result2)
print("String 3 multiplied by 2:", result3)
#4) wap to print string in revrese order using reverse indexing, using loop
def reverse_string():
str1=input("Enter a string:")
for i in range(len(str1)-1,-1,-1):
print(str1[i],end="")
#5) wap to check particular substring is present in given string or not by using in and not in operator
def check_substring():
str1 = input("Enter a string: ")
substr = input("Enter substring to check: ")
if substr in str1:
print(f"'{substr}' is present in '{str1}'")
else:
print(f"'{substr}' is not present in '{str1}'")
print("Concatenate Strings")
concatenate_strings()
print("\nSubstring Slice")
substring_slice()
print("\nString Multiplication")
string_multiplication()
print("\nReverse String")
reverse_string()
print("\nCheck Substring")
check_substring()