-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringquestion.py
More file actions
288 lines (244 loc) · 6.32 KB
/
Copy pathStringquestion.py
File metadata and controls
288 lines (244 loc) · 6.32 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# ## Question-31--Print string in reverse,its length,in uppercase,lowercase and copy into another string
# s = "shrey"
# print(f"reverse string -->{s[::-1]}")
# # print(f"length of string-->{len(s)}")
# # print(f"String in upper format-->{s.upper()}")
# # print(f"String in lower format -- >{s.lower()}")
# # ##Question 32--> Arrange String character such that lowercase letters should come first
# # s = "ShEry"
# # lower = ""
# # upper = ""
# # for i in s :
# # if i.islower():
# # lower = lower+i
# # elif i.isupper():
# # upper = upper + i
# # print(lower + upper) ###--->> this method of string addition is clled stirng concatenation
# # print(upper + lower)
# # ##Question 33-->Count all letters, digits, and special symbols from a given string
# # #Given: str1 = "P@#yn26at^&i5ve"
# # #Expected Outcome:
# # #Total counts of chars, digits, and symbols
# # #Chars = 8
# # #Digits = 3
# # #Symbol = 4
# # str1 = "P@#yn26at^&i5ve"
# # alpha = 0
# # digit = 0
# # special = 0
# # for i in str1:
# # if i.isalpha ():
# # alpha = alpha + 1
# # elif i.isdigit():
# # digit = digit +1
# # else:
# # special = special + 1
# # print(f"alphabet count:{alpha}")
# # print(f"digit count:{digit}")
# # print(f"Special count:{special}")
# # print(f"Total:{len(str1)}")
# # ## 34 .Compare two strings without using inbuilt functionsx
# # str1 = "hello"
# # str2 = "hello"
# # if len(str1) == len(str2):
# # for i in range(len(str1)):
# # if str1[i] != str2[i]:
# # print("string are not same")
# # break
# # else:
# # print("string are same")
# # else:
# # print("both string are of not the same length")
# ##35. count Vowels from given String
# str1 = "DEEPAK"
# vowels = "aeiouAEIOU"
# count = 0
# for i in str1:
# if i in vowels:
# count += 1
# print(f"Total count of vowels are:{count}")
# ##through function method
# def countvowels():
# str1 = "DEEPAK"
# vowels = "aeiouAEIOU"
# count = 0
# for i in str1:
# if i in vowels:
# count += 1
# print(f"Total count of vowels are:{count}")
# countvowels()
# ### through return
# def countvowels():
# str1 = "DEEPAK"
# vowels = "aeiouAEIOU"
# count = 0
# for i in str1:
# if i in vowels:
# count += 1
# return f"Total count of vowels are:{count}"
# print(countvowels())
# ### question--36 Reverse a string
# # s = "Hello"
# # rev = (s[::-1])
# # print(rev)
# rev = ""
# for i in s[: : -1]:
# rev = rev + i
# print(rev)
# ## question 37--Check string is Pallindrome or not
# n = "Madam"
# rev = (n[: : -1])
# if n== rev:
# print(f"{n} is pallindrome")
# else:
# print(f"{n} is not a pallindrome")
# ## function method
# def pallindrome(n):
# rev = n[: : -1]
# if n == rev:
# print(f"{n} is an pallindrome")
# else:
# print(f"{n} is not a pallindrome")
# pallindrome("madam")
## through return method
# def pallindrome(n):
# rev = (n[: : -1])
# if n == rev:
# return f"{n} is an pallindrome"
# else:
# return f"{n} is not a pallindrome"
# print(pallindrome("madam"))
# ## count number of vowels and consonant from a string
# s = "deepak"
# vowels = 0
# consonant = 0
# for i in s:
# if i in "aeiouAEIOU":
# vowels += 1
# else:
# consonant += 1
# print(f"Total vowels are:{vowels}")
# print(f"Total consonant are:{consonant}")
# ## function method
# def fun1(s):
# vowel = 0
# consonant = 0
# if i in "aeiouAEIOU":
# vowels += 1
# else:
# consonant += 1
# print(vowels)
# print(consonant)
#### 17th april
##count the number of digit in a number
# n = 1234
# count = 0
# while n > 0:
# #digit = n% 10
# count = count + 1
# n = n//10
# print(count)
# ##function
# def count(n):
# n= 256
# count = 0
# while n > 0:
# digit = n%10
# count = count + 1
# n = n//10
# print(count)
# count(256)
# ### if we use return inside a function method we have to write print in last like below or if we use return inside a function method it wil act like a mini variable and untill unless we didn't print the variable the output will not be displayed
# def count(n):
# n= 2567890
# count = 0
# while n > 0:
# digit = n%10
# count = count + 1
# n = n//10
# return (count)
# print(count(2567890))
## find the sum of digits if a number (e.g., 123-->6)
# n = 123
# sum = 0
# while n > 0:
# digit= n % 10
# sum = sum + digit
# n = n//10
# print(f"soum of digit is",{sum})
# ## function method
# def check_sum (n:int):
# n = 123
# sum = 0
# while n > 0:
# digit = n % 10
# sum = sum + digit
# n = n//10
# return (f"sum of digit is",{sum})
# print(check_sum(123))
##check whether number is armstrong number is not
# n = 153
# sum = 0
# copy = n
# while n > 0:
# digit = n % 10
# power = digit ** 3
# sum = sum + power
# n = n//10
# if copy == sum:
# print("Armstrong number")
# else:
# print("not an armstrong number")
# ## function
# def armstrong(n):
# sum = 0
# copy = n
# while n > 0:
# digit = n % 10
# power = digit ** 3
# sum = sum + power
# n = n // 10
# if copy == sum :
# print("it is an armstrong number")
# else:
# print("it is not an armstrong number")
# armstrong(153)
# armstrong(1534)
# armstrong(256)
# armstrong(123)
# armstrong(370)
# armstrong(371)
## through return method
# def armstrong(n):
# sum = 0
# copy = n
# while n > 0:
# digit = n % 10
# power = digit ** 3
# sum = sum + power
# n = n // 10
# if copy == sum :
# return f"it is an armstrong number"
# else:
# return f"it is not an armstrong number"
# print(armstrong(373))
### Iterative statement practice
##16 -- accept an integer and print hello world n times
# n = int(input("enter your number"))
# while n > 0:
# print("HELLO WORLD")
##
# n = int(input())
# for i in range(n):
# print("hello world")
## through function
# def hello_world(n):
# while n > 0:
# print("hello world")
# hello_world(9)
## through return method
def hello_world(n):
while n > 0:
return f"hello world"
n = int(input("enter your number"))
print(hello_world(n))