0% found this document useful (0 votes)
4 views

"Enter A String:": STR Input Print STR 2

Uploaded by

vagejan856
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

"Enter A String:": STR Input Print STR 2

Uploaded by

vagejan856
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#Display alternate characters in the sentence.

str = input("Enter a string:")


print(str[::2])

Enter a string:shubham chaudhar


suhmcada

#Extract words from the sentence, put them in a list, and display the
list.

str = input ("Enter string:")


print(str.split())

Enter string:shubham rajendra chaudhar


['shubham', 'rajendra', 'chaudhar']

#Convert all words to uppercase.

str = input("Enter the string:")


print(str.upper())

Enter the string:shubham chaudhar


SHUBHAM CHAUDHAR

#Enter a new string from the user and check if the entered string is
present in the original sentence

str1 = input("enter 1st string:")


str2 = input("enter 2nd string:")

if(str2 in str1):
print("New string is present in string 1")
else:
print("new string is not present in string 1")

enter 1st string:stttt


enter 2nd string:hjio
new string is not present in string 1

# Number Manipulation Program:


#Write a program that accepts a number from the user and performs the
following operations:

#a) Display the total number of digits in the number.

n = int(input("enter the number:"))


cnt = 0
while(n>0):
n= n//10
cnt += 1
print("number of digits is:",cnt)

n = int(input("enter the number:"))


cnt = 0
while(n>0):
n= n//10
cnt += 1
print("number of digits is:",cnt)

num_digits = len(str(abs(number))) # Counting the digits


print(f"Total number of digits: {num_digits}")

#Convert all words to uppercase.

str = input("Enter the string:")


print(str.upper())

#Display whether the entered number is positive, negative, or zero.

n = int(input("Enter the number"))


if(n<0):
print(n," is -ve")
elif(n>0):
print(n," is +ve")
else:
print(n," is zero")

def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True

if is_prime(number):
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")

You might also like