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

program file sem 1 classs 12

Uploaded by

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

program file sem 1 classs 12

Uploaded by

Naksh Yedke
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Program File

Program1-
st="hello good morning"
n=st.count('o')
print(n)

Program2-
st= input("Enter a string: ")
newst= ""
for i in st:
if i in "AEIOUaeiou":
newst+= '*'
else:
newst += i
print("String with vowels replaced by '*':",
newst)

Program3-
st = input("Enter a string: ")
newst = ""
for i in reversed(st):
newst += i
print("Reversed string:", newst)
Program4-
phone_number = input("Enter a phone number
(in the format XXX-XXX-XXXX): ")
if len(phone_number) == 12 and phone_num-
ber[3] == '-' and phone_number[7] == '-':
digits= phone_number.replace('-', '')
if digits.isdigit():
print("The phone number is in valid format
and is valid.")
else:
print("The phone number contains non-
digit characters and is invalid.")
else:
print("The phone number is not in the cor-
rect format and is invalid.")

Program 5-
sentences = input("Type one or more sen-
tences followed by 'enter': ")
words = sentences.split()
char_count = len(sentences)
alphanumeric_count = sum(c.isalnum() for c in
sentences)
percentage_alphanumeric =
(alphanumeric_count / char_count) * 100
print("Original Sentence(s):")
print(sentences)
print("\nStatistics:")
print("Number of Words:", len(words))
print("Number of Characters:", char_count)
print("Percentage of Alphanumeric Characters:
{:.2f}%".format(percentage_alphanumeric))

Program6-
while True:
s = input("Enter a sentence or 'q' to quit: ")
if s == 'q':
break
s2 = ''
for i in s:
if i.islower():
s2+= i.upper()
elif i.isupper():
s2 += i.lower()
else:
s2 +=i
print("Converted Sentence:", s2)

Program7-
integer_input = int(input("Enter an integer: "))
string_input = input("Enter a string: ")
extracted_digits = ""
for char in string_input:
if char.isdigit():
extracted_digits += char
if not extracted_digits:
extracted_digits = "0"
result = integer_input + int(extracted_digits)
print(f"{integer_input}+
{extracted_digits}={result}")
Program8-
number = int(input("Enter a number (1 to
3999): "))
if 1 <= number <= 3999:
roman_numeral = ""
symbols = ["M", "D", "C", "L", "X", "V", "I"]
values = [1000, 500, 100, 50, 10, 5, 1]
i=0
while number > 0:
quotient = number // values[i]
remainder = number % values[i]
roman_numeral += symbols[i] * quotient
if i % 2 == 0 and i < 6 and remainder >=
values[i] - values[i + 2]:
roman_numeral += symbols[i + 2] +
symbols[i]
remainder -= values[i] - values[i + 2]
number = remainder
i += 1
print(f"The Roman numeral equivalent of
{number} is {roman_numeral}.")
else:
print("Please enter a number between 1 and
3999.")

Program 9-
st = input("Enter a string with single spaces be-
tween words: ")
count = 1
for i in st:
if i == ' ':
count += 1
print("Estimated number of words in the
string:", count)

Program 10-
formula = input("Enter a formula with brackets:
")
balance = 0
for i in formula:
if i == '(':
balance += 1
elif i == ')':
balance -= 1
if balance == 0:
print("The formula has the same number of
opening and closing parentheses.")
else:
print("The formula does not have the same
number of opening and closing parentheses.”)

Program 11-

line_of_text = input("Enter a line of text: ")


vowel_count = 0
vowels = "AEIOUaeiou"
for i in line_of_text:
if i in vowels:
vowel_count += 1
print("Number of vowels in the line of text:",
vowel_count)
Program 12-

line_of_text = input("Enter a line of text: ")


words = line_of_text.split()
longest_word = ""
max_length = 0
for word in words:
cleaned_word = ''.join(e for e in word if
e.isalnum())
word_length = len(cleaned_word)
if word_length > max_length:
longest_word = cleaned_word
max_length = word_length
print("The longest word in the line of text is:",
longest_word)

Program13-
line_of_text = input("Enter a line of text: ")
words = line_of_text.split()
reversed_words = []
for word in words:
reversed_word = word[::-1]
reversed_words.append(reversed_word)
new_line_of_text = ' '.join(reversed_words)
print("New line of text with reversed words:")
print(new_line_of_text)

You might also like