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

Python Practical - 2 (Code)

Uploaded by

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

Python Practical - 2 (Code)

Uploaded by

vsonavane614
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical no.

2A [Code]

# Program to count number of alphabets, numeric, alphanumeric, vowels, consonants and


Special Characters

str = input("Enter a string : ")


n = len(str)
alpha = vowel = conso = num = spchar = 0

for i in range(0, n):


x = str[i]

if x.isalpha():
alpha += 1
if x.lower() in ('a', 'e', 'i', 'o', 'u'):
vowel += 1
else:
conso += 1

elif x.isnumeric():
num += 1

else:
spchar += 1

print(f"The string '{str}' contains ")


print(f"No. of Alphabets : {alpha}")
print(f"No. of Numeric : {num}")
print(f"No. of Alpha-Numeric : {alpha + num}")
print(f"No. of Vowel : {vowel}")
print(f"No. of Consonants : {conso}")
print(f"No. of Special Characters : {spchar}")

******OUTPUT******
PS C:\Users\kambl\OneDrive\Desktop\Programs\ARK_PY> python practical_2A.py
Enter a string : Tess@120
The string 'Tess@120' contains
No. of Alphabets : 4
No. of Numeric : 3
No. of Alpha-Numeric : 7
No. of Vowel : 1
No. of Consonants : 3
No. of Special Characters : 1
Practical no. 2B [Code]

#Program for arithmetic operations in two numbers

num1 = int(input("Enter first number : "))


num2 = int(input("Enter second number : "))

add = num1 + num2


sub = num1 - num2
mul = num1 * num2
div = num1 / num2
floor_div = num1 // num2
pow = num1 ** num2
mod = num1 % num2

print(f"Addition of {num1} and {num2} is {add}")


print(f"Subtraction of {num1} and {num2} is {sub}")
print(f"Multiplication of {num1} and {num2} is {mul}")
print(f"Division of {num1} and {num2} is {div}")
print(f"Floor Division of {num1} and {num2} is {floor_div}")
print(f"Power of {num1} and {num2} is {pow}")
print(f"Modulus of {num1} and {num2} is {mod}")

******OUTPUT******
PS C:\Users\kambl\OneDrive\Desktop\Programs\ARK_PY> python practical_2B.py
Enter first number : 6
Enter second number : 2
Addition of 6 and 2 is 8
Subtraction of 6 and 2 is 4
Multiplication of 6 and 2 is 12
Division of 6 and 2 is 3.0
Floor Division of 6 and 2 is 3
Power of 6 and 2 is 36
Modulus of 6 and 2 is 0

You might also like