Posts

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 to generate pattern using nested loop

Image
Q) Python program to generate pattern using nested loop . Ans) def a(): for i in range(1,n+1): for j in range(1,i+1): print("*",end="") print() n=int(input("Enter number of rows:")) print(a()) Output:

Python program to print the following series:x-x^2/2!+x^3/3!-x^4/4!+...+x^n/n!

Image
Q) Python program to print the following series :x-x^2/2!+x^3/3!-x^4/4!+...+x^n/n!. Ans:  n=int(input('enter the power:')) x=int(input("enter the base:")) a=0 b=1 for i in range(1,n+1): fact=1 for j in range(1,i+1): fact*=j c=((x**i)/fact) a=a+c*b b=b*(-1) print("sum of series:",round(a,2)) OUTPUT :

Python program to print the sum of series: 1+x^2+x^3+...+x^n.

Image
 Q)  Python program to print the sum of    series: 1+x^2+x^3+...+x^n . Ans:  n=int(input("enter the power:")) x=int(input("enter the base:"))  a=1 for i in range(2,n+1): a=a+(x**i) print("sum of series:",a) OUTPUT: Thanks for visiting ...

Python program to swap the values of two variable

  1) Write a Python Program  to swap the values of  two variable? Ans:- #Program for swapping to variables: a=9 b=2 print("Before Swapping:-") print('a:',a) print("b:",b) a,b=b,a print("After Swapping:-") print("a:",a) print("b:",b) Thanks For Visiting...

Python Program for Stack

Image
  1) Write Python Program for simple Stack operation ?  Ans: #Program for Stack import sys s=[] def push():      a=int(input("enter the num:"))      s.append(a)      print("\nPush Operation successfully") def pop():      if s==[]:           print("stack is empty:")      else:           print("Poped values is",s.pop()) def display():      if s==[]:           print("Stack is empty!")      else:           print("your entered stack is ",s) while True:      print('\n1:Push()\n2:pop()\n3:display()\n4:Exit\n')      ch=int(input("Enter ur choice:"))      if ch==1:           push()      elif ch==2:           pop()      elif ch==3:           display()      elif ch==4:           sys.exit()      else:           print("u made a wrong choice:")             THANKS FOR VISITING...

Python Program for Calculator

Image
  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/

Python Program to send WhatsApp message

Image
 1) Python Program to send WhatsApp message Ans : ''' First of all u have to install a module name pywhatkit   ,for this open command prompt and Internet should be available and  write:   pip install pywhatkit ''' Now code :- import pywhatkit pywhatkit.sendwhatmsg('<Phone no>','<Message>',<time(Hour)>,time(minute)) # write that phone no to whom u want to send the message and it must be with in the inverted commas. OUTPUT :-                         THANKS FOR VISITING . . . . . .

Python Program to rotate the screen of your PC

1) Python program to rotate screen of your PC : Ans: '''  f irst of all u have to install modules like rotatescreen and win32api .  for this , open  command prompt  and internet should be available and write the command:          pip install rotatescreen         pip install win32api    ''' Now code :- import rotatescreen import time n=int(input("Enter no of time u want to rotate ur screen:")) a=rotatescreen.get_primary_display() for i in range(n):     time.sleep(1)          a.rotate_to(i*90 %360)     Output :       >>> U will get the rotatory motion of ur PC screen and in order to stop the execution of program ,u just have to press ctrl+F2. and if Ur screen stops  at wrong side then Press shift+f10 to keep it running for few more time(but this time it moves slowly) and when it came to a right direction  press ctrl+F2 . Thanks for visiting . . . . . . 

Hack for chrome dino game(Cheats)

Image
 Fun with chrome dino game  By applying these code you can make changes into dino game: step1:  Go to chrome browser ( Suggestion : it will be good if u open it in incognito mode ) . step2: search: chrome://dino. step3: press  ctrl+shift+i ,  choose console  option. step4:  now write code in that console. step5:   code are as follow:      (a) for controlling speed write :  Runner.instance_.setSpeed(n)                               where n=+ve integer.                               for eg:  Runner.instance_.setSpeed(10000) ( b )  for jump ( high or low ) :  Runner.instance_.tRex.config.GRAVITY=n                    where  n =+ve real no ( suggestion: Don't let 'n' to be very big no ).          for eg :     Runner.instance_.tRex.config.GRAVITY=0.1 (c) if u want to input yours own distance then follow this code:     code is: Runner.instance_.distance=n / Runner.instance_.distanceMeter.config.COEFFICIENT                              where n=+ve integer.         for eg :   Run

Python Program for fibonacci series

Image
 1)Write a Python Program for Fibonacci series? Ans :  n=int(input("Enter the total numbers in series: ")) a,b=0,1 for i in range(n):      print(a)      a,b=b,a+b                                                                     Or def fib(n):     a,b=0,1     for i in range(n):         print(a)         a,b=b,a+b n=int(input('Enter the total numbers in series:')) print(fib(n))           Thanks for visiting....

Python program to check whether a number is prime or not

Image
 1)Write a Python program to check whether a number is prime or not? Ans : a=int(input("enter the num:")) for i in range(2,a):     if a%i==0:         print("No!it is not a prime number")         break else:     print("Yes! it is prime number")                                             Or while True:      a=int(input("enter the num:"))      for i in range(2,a):          if a%i==0:                print("No!it is not a prime number")                break      else:           print("Yes! it is prime number")                                             Thanks for visiting ...

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

 1)Write a Python program to read a text file and display a no of vowels, consonant, uppercase, lowercase character in file? Ans : file=open('Ayush.txt')  #by default it opens in reading mode a=file.read() vowels=0 consonants=0 uppercase=0 lowercase=0 for b in a:     if b.isupper():         uppercase+=1     elif b.islower():         lowercase+=1     b=b.lower()     if b in 'aeiou':         vowels+=1     elif b in 'bcdfghjklmnpqrstvwxz':         consonants+=1     else:          pass print('no of vowels:',vowels) print('no of consonants:',consonants) print('no of uppercase:',uppercase) print('no of lowercase:',lowercase)                    Thanks for visiting......

Python program to read a text file and display each word separated by a#

 1)Write a Python program to read a text file and display each word        separated by a#? Ans : file=open('Ayush.txt')       #by default it opens in reading mode a=file.readlines() for line in a:     b=line.split()     for c in b:         print(c+'a#',end='')     print('') Thanks for visiting..................

Python Program to print even number in list

Image
 1)Write a Python Program to print even number in list? Ans : def even1():     even=[]     for i in a:         if i%2==0:             even.append(i)         else:             pass     return even a=[1,2,3,4,5,6] print(even1())                                                                               Thanks  for visiting....

Python program to detect the total number of local Variable

Image
 1)Write a Python program to detect the total number of local                          Variable? Ans : def ayush():     a=1     b=2     c='Jai Hind'     print("I love my india ") print(ayush.__code__.co_nlocals)                                   Thanks for Visiting............

Python program to return the sum of odd number in list

Image
  1) Write Python program to return the sum of odd number in list? Ans : def sum_of_odd_no_in_list(a):     odd=[]     even=[]     for i in a:         if i%2==0:             even.append(i)         elif i%2!=0:             odd.append(i)         else:             pass     n=sum(odd)     return n a=[1,2,3,4,5,6] print(sum_of_odd_no_in_list(a))                                                                                     Thanks for visiting...

Python program to removes duplicate from list

Image
1)Write a  Python program to removes duplicate from list? Ans : def remove_duplicate(a):     return list(set(a)) p=[1,2,3,4,5,4,3,2,1] print(remove_duplicate(p)) Thanks for visiting....

Python program to access function inside a function

Image
  1)Write Python program to access function inside a function? Ans: def test(a):     def test1(b):         nonlocal a         a+=1         return a+b     return test1 fun=test(4) print(fun(4)) Thanks for visiting......

Python program that takes a list and return a new list with unique element in list

Image
 1)Write a Python program that takes a list and return a new list with      unique element in list? Ans :  def unique_list(a):     b=list(set(a))     return b a=[1,2,3,4,5,1,2,3,4,5] print('Entered List:',a) print('Modified list',unique_list(a)) Thanks for visiting ........

Python program to calculate the total number of uppercase, lowercase ,digit and special_character

Image
 1)Write a Python program to calculate number of uppercase, lowercase, digit and special character ? Ans : def case_checker(a):     upper=0     lower=0     digit=0     special_character=0     for i in a:         if i.isupper():             upper+=1         elif i.islower():             lower+=1         elif i.isdigit():             digit+=1         else:             special_character+=1     print("Total uppercase:",upper)     print("Total lowercase:",lower)     print("Total digitcase:",digit)     print("Total special_character:",special_character) a=input("Enter the String: ") print(case_checker(a)) Thanks for visiting 

Python Program to calculate the factorial of number

Image
 1)write a python Program to calculate the factorial of number? Ans: def factorial(a):     f=1     for i in range(1,a+1):         f*=i                                  # f=f*i     return f a=int(input("Enter the number: ")) print(factorial(a))                                                                                             Or import math n=int(input("enter the number: ")) print("factorial of ",n, 'is', math.factorial(n))                                                      Thanks for Visiting...

Python program to reverse a string

Image
  1)Write a Python program to reverse a string? Ans : def reverse_string(a):     return a[::-1] a=input("Enter the strings:") print(reverse_string(a))                                                                                                 Or a=input('enter string:') print(a[::-1])                                         Thanks for visiting...

Python Program to multiply all number in a list

Image
 1) Python Program to multiply all number in a list? Ans :  def multiply_num_list(a):     n=1     for i in list:         n=n*i     return n list=[1,2,3,4,5] print(multiply_num_list(list)) Thanks for visiting the site...

Python program to find sum of all number in list

Image
  1) Write Python program to find the sum of all number in list? Ans :   def sum_list(a):     b=sum(a)     return b list=[1,2,3,4,5] print(sum_list(list))                                                                                 Or list=[1,2,3,4,5] print(sum(list)) Thanks for visiting...

program for Max of three number in Python

Image
1) W rite a python program to find Max of three number ? Ans :        def max_of_3_num(a,b,c):     if a>b and a>c:          return 'Max of three num is', a     el if b>a and b>c:         return 'Max of three num is', b     else:          return 'Max of three num is', c a=int(input("Enter the first num :")) b=int(input("Enter the second num :")) c=int(input("Enter the third num :")) print(max_of_3_num(a,b,c))                                                                      Or a=int(input("Enter the first num :")) b=int(input("Enter the second num :")) c=int(input("Enter the third num :")) if a>b and a>c:      print('Max of three num is', a) elif b>a and b>c:     print( 'Max of three num is', b) else:     print('Max of three num is', c) Thanks for visiting this site