Professional Documents
Culture Documents
sum += digit
n = n// 10
return sum
add = sum_of_digits(n)
print("The sum of digits in {n} is”,add)
def generate_fibonacci(n):
fibonacci_sequence = [0, 1]
return fibonacci_sequence
if num_terms <= 0:
print("Please enter a positive integer.")
else:
fibonacci_sequence = generate_fibonacci(num_terms)
print("Fibonacci Sequence:")
for number in fibonacci_sequence:
print(number)
num = int(input("Enter a number: "))
even_sum = 0
odd_sum = 0
if found:
print(f"{element_to_search} was found in the list.")
else:
print(f"{element_to_search} was not found in the list.")
numbers = eval(input(“enter numbers in a list”))
for i in range(len(numbers)):
if 0 <= numbers[i] <= 9:
numbers[i] *= 2
count = 0
for line in file:
if line.strip() and line[0].isupper():
count += 1
print(“Number of lines starting with an uppercase letter: {count}')
with open('STUD.DAT', 'r') as file:
text = file.read()
word_list = text.split()
count_hello = word_list.count("hello")
content = file.read()
for char in content:
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
print("Uppercase letters count:", uppercase_count)
print("Lowercase letters count:", lowercase_count)
def count_uppercase_vowels_in_file(STUD.DAT):
uppercase_vowels = "AEIOU"
vowel_count = 0
try:
with open(file_path, 'r') as file:
text = file.read()
for char in text:
if char in uppercase_vowels:
vowel_count += 1
except FileNotFoundError:
print("File not found.")
return vowel_count
file_path = "STUD.DAT"
uppercase_vowel_count = count_uppercase_vowels_in_file(file_path)
print("Number of uppercase vowels in the file: {uppercase_vowel_count}")
import csv
csv_file = 'STUD.csv'