0% found this document useful (0 votes)
8 views11 pages

Shourya Cs

The document contains a series of Python programs that demonstrate various functionalities, including counting vowels in a string, printing patterns, counting positive and negative numbers in a list, calculating the difference between sums of odd and even digits, and checking if the count of divisors is even or odd. It also includes programs for displaying the Fibonacci series, performing arithmetic operations, calculating factorials and sums, implementing mathematical functions, searching for words in sentences, and printing a series based on input values. Each program is accompanied by example outputs to illustrate their functionality.

Uploaded by

Manish Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Shourya Cs

The document contains a series of Python programs that demonstrate various functionalities, including counting vowels in a string, printing patterns, counting positive and negative numbers in a list, calculating the difference between sums of odd and even digits, and checking if the count of divisors is even or odd. It also includes programs for displaying the Fibonacci series, performing arithmetic operations, calculating factorials and sums, implementing mathematical functions, searching for words in sentences, and printing a series based on input values. Each program is accompanied by example outputs to illustrate their functionality.

Uploaded by

Manish Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Write a Python program to print a string


and the number of the vowels present in it.

string = input("Enter a string: ")


vowels = "aeiouAEIOU"
count = 0
for char in string:
if char in vowels:
count += 1
print("Input String:", string)
print("Number of vowels:", count)

Output:
Enter a string: hello world
Input String: hello world
Number of vowels: 3
2. Write a Python program to print a given
pattern.

for i in range(5, 0, -1):


for j in range(i, 0, -1):
print(j, end=" ")
print()

Output:
54321
4321
321
21
1
3. Write a Python program to count
positive and negative number in a list.

numbers = [1, -3, 5, -2, 0, 6, -7]


positive = 0
negative = 0
for num in numbers:
if num > 0:
positive += 1
elif num < 0:
negative += 1
print("Positive numbers:", positive)
print("Negative numbers:", negative)

Output:
Positive numbers: 3
Negative numbers: 3
4. Write a Python program to print the
difference between sum of odd and even
digits.

num = input("Enter a number: ")


sum_even = 0
sum_odd = 0
for digit in num:
if digit.isdigit():
if int(digit) % 2 == 0:
sum_even += int(digit)
else:
sum_odd += int(digit)
print("Difference:", abs(sum_odd -
sum_even))

Output:
Enter a number: 12345
Difference: 3
5. Write a Python program to check if
count of divisor is even or odd.

n = int(input("Enter a number: "))


count = 0
for i in range(1, n + 1):
if n % i == 0:
count += 1
if count % 2 == 0:
print("Even number of divisors")
else:
print("Odd number of divisors")

Output:
Enter a number: 10
Even number of divisors
6. Write a Python program to display
Fibonacci series up to ‘n’ numbers.

n = int(input("Enter n: "))
a, b = 0, 1
count = 0
while count < n:
print(a, end=" ")
a, b = b, a + b
count += 1

Output:
Enter n: 5
01123
7. Create a menu driven program to
perform arithmetic operations.
print("1. Add\n2. Subtract\n3. Multiply\n4. Divide")
choice = int(input("Enter choice: "))
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if choice == 1:
print("Sum =", a + b)
elif choice == 2:
print("Difference =", a - b)
elif choice == 3:
print("Product =", a * b)
elif choice == 4:
if b != 0:
print("Quotient =", a / b)
else:
print("Cannot divide by zero")
else:
print("Invalid choice")
Output:
1. Add
2. Subtract
3. Multiply
4. Divide
Enter choice: 1
Enter first number: 5
Enter second number: 3
Sum = 8
8. Creating a menu driven program to
find factorial and sum of list of numbers
using function.

print("1. Factorial\n2. Sum of List")


choice = int(input("Enter your choice: "))
if choice == 1:
n = int(input("Enter a number: "))
fact = 1
for i in range(1, n + 1):
fact *= i
print("Factorial:", fact)
elif choice == 2:
nums = list(map(int, input("Enter numbers
separated by space: ").split()))
total = 0
for num in nums:
total += num
print("Sum of list:", total)
else:
print("Invalid choice")
Output:
1. Factorial
2. Sum of List
Enter your choice: 1
Enter a number: 4
Factorial: 24
9. Creating a Python program to
implement mathematical functions.

import math
x = int(input("Enter a number: "))
print("Square root:", math.sqrt(x))
print("Power (x^2):", math.pow(x, 2))
print("Ceil:", math.ceil(math.sqrt(x)))
print("Floor:",
math.floor(math.sqrt(x)))

Output:
Enter a number: 10
Square root: 3.162...
Power (x^2): 100.0
Ceil: 4
Floor: 3
10. Write a Python program to search any
word in given string sentences.

sentence = input("Enter a sentence:


")
word = input("Enter word to search:
")
if word in sentence:
print("Word found")
else:
print("Word not found")

Output:
Enter a sentence: this is a test
Enter word to search: test
Word found
11. Write a Python program to input value of
X and n print the series along with its sum.

x = int(input("Enter value of x: "))


n = int(input("Enter value of n: "))
sum_series = 0
for i in range(1, n + 1):
term = x ** i
print(term, end=" ")
sum_series += term
print("\nSum of series:", sum_series)

Output:
Enter value of x: 2
Enter value of n: 3
248
Sum of series: 14

You might also like