Skip to main content

GRADE XI - PYTHON STRINGS WITH PDF NOTES

 

GRADE XI  

PYTHON STRINGS

Practice Questions


           PPT LINK :PPT LINK


1. #Code to check number of words starting with Vowel (Without in-built function)

string = input("Enter a string: ")  

length = len(string)  

ctr = 0  

i = 0  # Pointer to traverse the string

while i < length:

    # Skip any extra spaces

    while i < length and string[i] == " ":

        i += 1

    # check if it starts with a vowel

    if i < length and string[i] in "aeiouAEIOU":

        ctr += 1

    # Move the pointer to the end of the current word

    while i < length and string[i] != " ":

        i += 1

print("Number of words starting with a vowel:", ctr)


With Split Function:

string = input("Enter a string: ")  

words = string.split()  

print("Words:", words)

ch = 0  

for word in words:

    # Check if the first letter of the word is a vowel

    if word[0].lower() in 'aeiou':

        ch += 1

print("Number of words starting with a vowel:", ch)


2.STRING PALINDROME

st = input("Enter a String: ")

flag=True

i = 0

j = len(st) - 1

while i <= j:

    if(st[i] != st[j]):

        flag=False

    i += 1

        j -= 1

if flag:

 print("The given string",st,"is a palindrome")

else:

 print("The given string",st,"is not a palindrome")


3.# Code to calculate the sum of digits in a string

str1 = "123abcd45"

print(str1)

    # Initialize a variable to store the sum of digits

sum_digit = 0   

for char in str1:    

    if char.isdigit():

            digit = int(char)

            sum_digit += digit

print(sum_digit)


4.Write a program to accept a string and convert all lower case letters to  upper case.

str=input("enter String - ")

newstr = " "  

for ch in str:

    if ch >= "a" and ch <= "z":

        newstr += chr(ord(ch)-32)

    else:

        newstr += ch

print("The converted String - ",newstr)


5. Write a menu driven program to accept a string and do the following operation on user ‘s  choice : 1. Display no. of vowels    2. Check for palindrome 3. Reverse string


6. Find the output: String Slicing
>>> str = "Computer Science"
>>> print(str[3:7]) 
>>> print(str[4:]) 
>>> print(str[0:]) 
>>> print(str[:6]) 
>>> print(str[1:10:2])
>>> print(str[4::2]) 
>>> print(str[:10:2])
>>> print(str[10:2:-1]) 

7. Write a program to accept a string with multiple words.
Form an integer by extracting all digits from the string in the order they occurred.

Eg: enter string- 8irst3dig4sum5
sting entered- 8irst3dig4sum5
Extracted number as integer - 8345

str= input("enter string-")
num= 0
for ch in str:
    if ch.isdigit():
        num= int(ch) + num*10
print("sting entered",str)
print("Extracted number as integer -",num)


Comments

Popular posts from this blog

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

GRADE XII CS - VIVA QUESTIONS

  VIVA QUESTIONS GRADE XII CS Dear All Be thorough with your project and practical files, as the viva can be asked from anywhere. Stay calm, don’t get nervous, and be confident in front of the examiner. 1. Tell me about your project. 2. Which concepts you have used for your project? 3. What do you mean by front end and back end? How they are important in developing any such projects? 4  Mention the modules and built-in functions you have used in your project. 5. Which real world problems are solved by your project? 6. Explain the most important feature of your project. 7. Name a few mutable data types of python. Lists, Sets, and Dictionaries 8. Name a few immutable data types of python. Strings, Tuples, Numeric 9. Name ordered and unordered data type of python. Ordered – String, List, Tuples Unordred – Set, Dictionaries 10. What is the significance of a pass statement in python? pass is no operation python statement. This is used where python requires syntax but logic requires...