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

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...