Вы находитесь на странице: 1из 5

Q. to accept two strings and bring the concatenated result.

a=input("Enter the first string:")

b=input("Enter the second string:")

print (a,end=" ")

print (b)

__________________________________________________________________________

Q. to accept two strings and count the number of alphabets and letters in the
string.

Input: a=input("Enter string1:")

x=input("Enter string2:")

alphacount=digitcount=0

alpha2count=digit2count=0

for b in a:

if b.isdigit():

digitcount+=1

elif b.isalpha():

alphacount+=1

print ("Number of digits in first string:",digitcount)

print ("Number of alphabets in first string:",alphacount)

for y in x:

if y.isdigit():

digit2count+=1

elif y.isalpha():

alpha2count+=1

print ("Number of digits in second string:",digit2count)

print ("Number of alphabets in second string:",alpha2count)


Output:

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
_____________________________________________________________________________________

Q. to accept a string and print it in reverse order.

Input: a=input("Enter string:")

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)

Output: Enter string:HEllo


2

______________________________________________________________________________Q.
To print the alternate letters of a string in upper and lowercase.

Input:
_________________________________________________________________________________________

Q. To check the palindrome of a string.


Input:

a=input("Enter a string:")

b=a[::-1]

if a==b:

print("It's a palindrome.")

else:

print ("It's not a palindrome.")

Output:
Enter a string:align Enter a string:madam

It's not a palindrome. It's a palindrome.

_________________________________________________________________________________________

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:

_________________________________________________________________________________________

Q. to accept 2 strings and copy it in a third string.

Input:

a=input("Enter the first string:")

b=input("Enter the second string:")

c=a+b

print("The combined string is",end=" ")

print (c)

Output:

Enter the first string:hello

Enter the second string:world

The combined string is helloworld


_________________________________________________________________________________________

Q. to enter a string and check if it’s a palindrome or not.

Input:

a=input("Enter the string:")

b=a[::-1]

if a==b:

print ("The string is a palindrome.")

else:

print ("The string is not a palindrome.")

Output:

1. Enter the string:hello

The string is not a palindrome.

2. Enter the string:madam

The string is a palindrome.

_____________________________________________________________________________________

Q.to accept a string and print every alternate characters of the string in capitals (example, madam).

_____________________________________________________________________________________

Q. To check if a number entered by the user is a palindrome or not.

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):

print ("The number is a palindrome.")


else:

print ("The number is not a palindrome.")

Output:

1. Enter a number:12321

The number is a palindrome.

2. Enter a number:56484

The number is not a palindrome.

_____________________________________________________________________________________

Q. To print the armstrong of a number.

_____________________________________________________________________________________

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.

Вам также может понравиться