Академический Документы
Профессиональный Документы
Культура Документы
print (b)
__________________________________________________________________________
Q. to accept two strings and count the number of alphabets and letters in the
string.
x=input("Enter string2:")
alphacount=digitcount=0
alpha2count=digit2count=0
for b in a:
if b.isdigit():
digitcount+=1
elif b.isalpha():
alphacount+=1
for y in x:
if y.isdigit():
digit2count+=1
elif y.isalpha():
alpha2count+=1
Enter string1:Hello1234
Enter string2:Bye7890
Number of digits in first string: 4
Number of alphabets in first string: 5
Number of digits in second string: 4
Number of alphabets in second string: 3
_____________________________________________________________________________________
b=a[::-1]
print(b)
Output: Enter string:hello
olleh
_________________________________________________________________________________
Q. to accept a string and count the number of upper and lowercase letters.
Input:
a=input("Enter string:")
lowercount=uppercount=0
for b in a:
if b.islower():
lowercount+=1
elif b.isupper():
uppercount+=1
print (uppercount)
print (lowercount)
______________________________________________________________________________Q.
To print the alternate letters of a string in upper and lowercase.
Input:
_________________________________________________________________________________________
a=input("Enter a string:")
b=a[::-1]
if a==b:
print("It's a palindrome.")
else:
Output:
Enter a string:align Enter a string:madam
_________________________________________________________________________________________
Q. WAP to accept a multiline string and count the number of ‘A’s in it. For example, ‘A’ boy is playing with ‘a’
ball(Only the ‘A’s are to be counted.)
Input:
_________________________________________________________________________________________
Input:
c=a+b
print (c)
Output:
Input:
b=a[::-1]
if a==b:
else:
Output:
_____________________________________________________________________________________
Q.to accept a string and print every alternate characters of the string in capitals (example, madam).
_____________________________________________________________________________________
Input:
a=int(input("Enter a number:"))
b=a
rev=0
while a>0:
dig=a%10
rev=rev*10+dig
a=a//10
if (b==rev):
Output:
1. Enter a number:12321
2. Enter a number:56484
_____________________________________________________________________________________
_____________________________________________________________________________________
Q. WAP that takes a string with multiple words and then capitalizes the first letter of each word, and
forms a new string out of it.