-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterview_question_3.py
More file actions
74 lines (64 loc) · 1.5 KB
/
interview_question_3.py
File metadata and controls
74 lines (64 loc) · 1.5 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
#count the small,capital,number,special character
str=input("Enter the word:")
small=0
capital=0
num=0
spec=0
for i in range(0,len(str)):
if str[i]>='A' and str[i]<='Z':
capital+=1
elif str[i]>='a' and str[i]<='z':
small+=1
elif str[i]>='0' and str[i]<='9':
num+=1
else:
spec+=1
print("Counts of Capital Letter:",capital)
print("Counts of Small Letter:",small)
print("Counts of numbers:",num)
print("Counts of special character:",spec)
#Count the number digits
numb=int(input("Enter the number:"))
count=0
while numb>0:
numb=numb//10
count+=1
print(count)
#Reverse the string
str1=input("Enter a string:")
str2=""
for i in str1:
str2=i+str2
print(str2)
#check palidrome or not
if (str1 == str2):
print("Given string is palindrome")
else:
print("Given string is not palindrome")
#Triangle with star
r=int(input("Enter the row:"))
for i in range(1,r+1):
for j in range(1,r-i+1):
print(end=" ")
for j in range(i,0,-1):
print("*",end=" ")
for j in range(2,i+1):
print("*",end=" ")
print()
#Sum of number in given digits
n=int(input("Enter a number:"))
sum=0
while n>0:
rem=n%10
sum=sum+rem
n//=10
print("Sum of given digit:",sum)
#Count the each word in string
string=input("Enter a sentence:")
word=input("Enter a word to count:")
words=string.split()
count=0
for w in words:
if w==word:
count=count+1
print(count)