Python program to count total number of vowel,consonant,lowercase,uppercase

Image
Q)Python program to count total no vowel,consonant,lowercase,uppercase. Ans: def ayush(str):     vowels = 0     consonant = 0     lower = 0     upper= 0     for i in range(0, len(str)):          ch = str[i]          if ch.isupper():         upper+=1         elif ch.islower():         lower+=1         if ( (ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z') ):          ch = ch.lower()         if (ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u'):         vowels += 1         else:         consonant += 1         else:         pass     print("Vowels:", vowels)     print("Consonant:", consonant)     print("lowercase:", lower)     print("uppercase:", upper)  str=input('enter the string:') ayush(str) Output:

Python Program for Calculator

 1) Write a Python Program For Calculator ?

Ans: Suggestion: Here I've given two codes in which first code is simple and 2nd code is little bit complex. but According to me, it will be good if u chooses 2nd code.

1st Program:


Code:


#Program for calculator:

a=int(input("Enter the first number:"))

b=int(input("Enter the Second number:"))

op=input("Enter Operator:")

result=0

if op=='+':

    result=a+b

elif op=='-':

    result=a-b

elif op=='*':

    result=a*b

elif op=='/':

    result=a/b

else:

    print("U Entered unknown operator:")

print(a,op,b,'=',result)


                                                                                Or
2nd Program:

Code:

#2nd Program for calculator:

import sys

def add():
    print("Addition:",a+b)

def sub():
    print("subtraction:",a-b)

def multiply():
    print("Multiplication:",a*b)

def divide():
    print("Divide:",a/b)

while True:
   print("1:Addition,\n2:subtraction,\n3:Multiplication,\n4:Division,\n5:Exit")

    ch=int(input("Enter the following question to perfom operations:"))

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

    b=int(input("Enter the 2nd number:"))
  
    if ch==1:
        add()

    elif ch==2:
        sub()

    elif ch==3:
        multiply()

    elif ch==4:
        divide()

    elif ch==5:
        sys.exit()

    else:
        print('\n******Invalid choice')

        print()

Output:



                                                THANKS FOR VISITING............

Comments

Popular posts from this blog

Python Program to rotate the screen of your PC

Python program to reverse a string

Python program to read a text file and display a no of vowels, consonant, uppercase, lowercase character in file