GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Notizen

PYTHON SAMPLE PROGRAMS

sneha singh Engineering CTET Englisch 2 Seiten

Inhalt der Notizen (2)

Seite 1

**************************PYTHON AMPLE PROGRAMS********************************************************

"""

*******************farenheit to celcius*************

temp= int(input("enter the temperature\n"))

far=5*(temp-32)/9

print("tempersture in celcius is : " + str(far))

"""

"""

***********LCM of Number**********************

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

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

minimum = min(num1, num2)

while(1):

if(minimum % num1 == 0 and minimum % num2 == 0):

print("LCM of two number is: ", minimum)

break

minimum += 1

"""

"""

#*****************reverse of number*********************

def rever(num):

#num=int(input("enter number to find reverse \n"))

rev =0

number=num

while(num>0):

rev=rev*10+num%10

num= int(num/10)

return rev

#print(" reverse of no. is :" +str(rev))

z=rever(562)

print(z)

if(rev==number):

print(" no is palindrome")

else :

print("no is not palindrome")

"""

"""

**************fibonacci series**********************

a=int(input("enter first number"))

b=int(input("enter second number"))

n=int(input("enter no. of terms"))

print(a,b,end=" ")

while(n-2):

c=a+b

a=b

b=c

print(c,end= " ")

n=n-1

"""

"""

******number which are not divisible by 2 or 3 in range 1 and 25*********

for i in range(1,25):

if((i%2!=0)&(i%3!=0)):

print(i)

"""

"""

*************sum of digit*********************

num=int(input("enter any number"))

sum=0

while(num>0):

sum=num%10+sum

num=num//10

print(str(sum))

"""

"""

def mul(num1,num2):

a=num1*num2

return a

z = mul(2,5)

print(z)

"""

"""""

import sys

balance=1000

print("your intial balance is Rs:"+str(balance))

def deposit():

c=int(input("enter amount to deposit\t"))

amount=balance+c

return amount

def withdrawn():

d=int(input("enter amount to withdrawn\t"))

amount=balance-d

return amount

while(1):

b=int(input("\nDo u want to deposit, Press 1\tDo you want to withdraw,Press 2\tfor Exit Press 3\n"))

if b==1:

balance=deposit()

print("your total balance is: \t "+str(balance))

elif b==2:

balance = withdrawn()

print("Your remaining balanace is: \n"+str(balance))

elif b==3:

print("Thankyou your available balance is :"+str(balance))

sys.exit()

"""

"""

def total(initial=5,*numbers,**keywords):

count=initial

for num in numbers:

count+=num

for key,value in keywords.items():

print(key,value)

for key in keywords:

count+=keywords[key]

return count

print(total(10,1,2,3,vegetables=50,fruits=100))

"""

"""*****************appending list****************

thislist = ['a', 'b', 'c']

thislist.append('d')

print(thislist)

"""

"""" *************************extend list*****************//

thislist = ['a', 'b', 'c']

thislist.extend('e')

print(thislist)

"""

"""***********insert list***************

thislist = ['a', 'b', 'c']

thislist.insert(2,'lalit')

print(thislist)

"""

"""**************remove*********************

thislist = ['a', 'b', 'c']

thislist.remove('b')

print(thislist)

"""

"""**********************pop list*********************

thislist = ['a', 'b', 'c','d']

thislist.pop(b)

print(thislist)

"""

"""********************indexlist**********

thislist = ['a', 'b', 'c','d']

print(thislist[0])

"""

"""**********************sort list*********************

thislist = ['a', 'e', 'z','d']

thislist.sort()

print(thislist)

"""

"""********************reverse list********************

thislist = ['a', 'e', 'z','d']

thislist.sort()

thislist.reverse()

print(thislist)

"""

"""************************stack operation*******************************

import sys

stack = ["c", "b", "a"]

def stackoperation_push():

a=str(input("enter lement to append"))

stack.append(a)

stack.append("y")

return stack

def stackoperation_pop():

a=int(input("enter lement to pop"))

stack.pop(a)

print(stack)

return stack

def main():

print("entering to main")

while(1):

a=int(input("enter your operation choice\n 1.push\n 2.pop\n"))

if(a==1):

value=stackoperation_push()

print(value)

elif(a==2):

value= stackoperation_pop()

print(value)

else:

sys.exit()

if __name__=='__main__':

main()

"""

"""*************************finding intersection*********************

def intersection(lst1, lst2):

return set(lst1).intersection(lst2)

lst1 = [1,3,6,78,35,55]

lst2 = [12,24,35,24,88,120,155]

print(intersection(lst1, lst2))

"""

"""************************remove duplicate in list*************************/

lst = [12,24,35,24,88,120,155,88,120,155]

list=[]

for i in lst:

if i not in list:

list.append(i)

print(list)

"""

"""**************************Using Dictionary**************************"""

"""

thisdict = {

"brand": "cyient",

"model": "manager",

"year": 1964

}

print("before change: "+str(thisdict))

thisdict["year"]=2019

print("after change: "+str(thisdict))

"""

"""*********************exception hNDLING*****************"""

"""

x="hello"

assert x == "hello"

assert x == "goodbye"

"""

"""

try:

print(x)

except NameError:

print("Variable x is not defined")

except:

print("Something else went wrong")

"""

"""********************file handling************************

f = open("brajesh.txt", "a")

f.write("welcome to file that have some content")

f.close()

f = open("brajesh.txt", "r")

print(f.read())

"""

""" ********* write a program to generate all sentences where subject is in ["i","you"]

and verb is in ["play","love"] and the object is in ["hockey,"football"]*******"""

"""

list1=["i","you"]

list2=["play","love"]

list3=["hockey","football"]

for i in list1:

for j in list2:

for k in list3:

print(i+""+j+""+k)

"""

""" ******write a prog to print the list after removing even numbers in[5,6,77,45,22,12,24]

can u use lambda function"""

"""

lst1=[5,6,77,45,22,12,24]

list=[]

for i in lst1:

if (i%2==0):

list.append(i)

print(list)

"""

"""

lst1=[5,6,77,45,22,12,24]

even_nos = list(filter(lambda x: (x % 2 == 0), lst1))

print("Even numbers in the list: ", even_nos)

"""

"""************concept of module************************************************

import push1

import sys

def main():

print("entering to main")

while(1):

a=int(input("enter your operation choice\n 1.push\n 2.pop\n 3.Exit From here"))

if(a==1):

value=push1.stackoperation_push()

print(value)

elif(a==2):

value= push1.stackoperation_pop()

print(value)

else:

sys.exit()

if __name__=='__main__':

main()

"""

"""********* generate no between 1 and 9 and ask the user to

guess the no then tell whether they guessed too llow ,high or exactly right************************"""

"""

import random

import sys

def main():

b=random.randint(1,9)

while(1):

a= int(input("enter no to guess between 1 and 9: "))

if(a>b):

print("your no is high: ")

elif(a<b):

print("your no is low: ")

elif(a==b):

print("you guessed corect no.")

sys.exit

if __name__=='__main__':

main()

"""

"""********************* write aprogram that takes list of no. a=[5,10,15,20,25] and

makes a new list of only first and last elements of given list ************"""

"""

a= [5, 10, 15, 20, 25]

def listend(x):

return [x[0], x[4]]

print(listend(a))

"""

"""**************WAP to ask the number and deter,mine whether it is prime or not*************"""

"""

num= int(input("enter nmber to check prime: "))

if(num==4):

print(num, "is not prime")

if num > 1:

for i in range(2, (num//2)):

if (num % i) == 0:

print(num,"is not a prime number")

break

else:

print(num, "is a prime number")

"""

"""*************matrix multiplication**************************"""

"""X = [[12,7],

[4 ,5]]

Y = [[12,7],

[4 ,5]]

result = [[0,0],

[0 ,0]]

for i in range(len(X)):

for j in range(len(Y[0])):

for k in range(len(Y)):

result[i][j] += X[i][k] * Y[k][j]

for r in result:

print(r)

"""

"""************print patterns*******************

1

22

333

4444

"""

"""

n = 5

for i in range(1, n):

for j in range(1, i+1):

print(i ,end="")

print("\r")

"""

"""*************** 1.The hangman progran randomly selects a secret word from a list of secret words

.The random module will provide this ability so line 1 in program imports it

2.The game here a random word (fruit name )is picked up from our collection and the player gets limitd chances to win the game

3.when a letter in that word is guessed correctly that letter position in the word is made visible.In this way,

all letter of word are to be guessed before all the chances are over.

4FOr convenience we have given length of word +2 chances .For example word to be guessed is mango ,

then user gets 5+2=7 chances as mango is five letter word.

***************************************************************************************************************"""

import random

fruitname = ['apple', 'orange', 'mango', 'peach', 'guava']

wordsToGuess = ""

activeGuess = list()

guesses = list()

lives = 7

print("Hint: enter fruitname start from letter 'a' 'o' 'm' 'p' 'g'" )

a=input("enter any fruitnmae")

wordsToGuess = random.choice(fruitname)

for i in range(len(wordsToGuess)):

print("word is "+str(wordsToGuess))

activeGuess.append("_")

while lives > 0 and ("_" in activeGuess):

print("You have", lives, "guesses")

print(activeGuess)

guess = input("Please enter your guess: ")

while guess in guesses:

print("invalid input")

guess = input("Please enter your guess: ")

guesses.append(guess)

if(guess in wordsToGuess):

for i in range(len(wordsToGuess)):

if(guess == wordsToGuess[i]):

activeGuess[i] = guess

else:

lives -=1

if lives > 0 and lives <7:

print("your find correct before your live gone finished\n" , activeGuess)

print(activeGuess)

elif lives == 7:

print("*your guess is correct *\n" , activeGuess)

print(activeGuess)

else:

print("Try Again!\n" , activeGuess)

Seite 2

"""

*******************farenheit to celcius*************

temp= int(input("enter the temperature\n"))

far=5*(temp-32)/9

print("tempersture in celcius is : " + str(far))

"""

"""

***********LCM of Number**********************

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

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

minimum = min(num1, num2)

while(1):

if(minimum % num1 == 0 and minimum % num2 == 0):

print("LCM of two number is: ", minimum)

break

minimum += 1

"""

"""

#*****************reverse of number*********************

def rever(num):

#num=int(input("enter number to find reverse \n"))

rev =0

number=num

while(num>0):

rev=rev*10+num%10

num= int(num/10)

return rev

#print(" reverse of no. is :" +str(rev))

z=rever(562)

print(z)

if(rev==number):

print(" no is palindrome")

else :

print("no is not palindrome")

"""

"""

**************fibonacci series**********************

a=int(input("enter first number"))

b=int(input("enter second number"))

n=int(input("enter no. of terms"))

print(a,b,end=" ")

while(n-2):

c=a+b

a=b

b=c

print(c,end= " ")

n=n-1

"""

"""

******number which are not divisible by 2 or 3 in range 1 and 25*********

for i in range(1,25):

if((i%2!=0)&(i%3!=0)):

print(i)

"""

"""

*************sum of digit*********************

num=int(input("enter any number"))

sum=0

while(num>0):

sum=num%10+sum

num=num//10

print(str(sum))

"""

"""

def mul(num1,num2):

a=num1*num2

return a

z = mul(2,5)

print(z)

"""

"""""

import sys

balance=1000

print("your intial balance is Rs:"+str(balance))

def deposit():

c=int(input("enter amount to deposit\t"))

amount=balance+c

return amount

def withdrawn():

d=int(input("enter amount to withdrawn\t"))

amount=balance-d

return amount

while(1):

b=int(input("\nDo u want to deposit, Press 1\tDo you want to withdraw,Press 2\tfor Exit Press 3\n"))

if b==1:

balance=deposit()

print("your total balance is: \t "+str(balance))

elif b==2:

balance = withdrawn()

print("Your remaining balanace is: \n"+str(balance))

elif b==3:

print("Thankyou your available balance is :"+str(balance))

sys.exit()

"""

"""

def total(initial=5,*numbers,**keywords):

count=initial

for num in numbers:

count+=num

for key,value in keywords.items():

print(key,value)

for key in keywords:

count+=keywords[key]

return count

print(total(10,1,2,3,vegetables=50,fruits=100))

"""

"""*****************appending list****************

thislist = ['a', 'b', 'c']

thislist.append('d')

print(thislist)

"""

"""" *************************extend list*****************//

thislist = ['a', 'b', 'c']

thislist.extend('e')

print(thislist)

"""

"""***********insert list***************

thislist = ['a', 'b', 'c']

thislist.insert(2,'lalit')

print(thislist)

"""

"""**************remove*********************

thislist = ['a', 'b', 'c']

thislist.remove('b')

print(thislist)

"""

"""**********************pop list*********************

thislist = ['a', 'b', 'c','d']

thislist.pop(b)

print(thislist)

"""

"""********************indexlist**********

thislist = ['a', 'b', 'c','d']

print(thislist[0])

"""

"""**********************sort list*********************

thislist = ['a', 'e', 'z','d']

thislist.sort()

print(thislist)

"""

"""********************reverse list********************

thislist = ['a', 'e', 'z','d']

thislist.sort()

thislist.reverse()

print(thislist)

"""

"""************************stack operation*******************************

import sys

stack = ["c", "b", "a"]

def stackoperation_push():

a=str(input("enter lement to append"))

stack.append(a)

stack.append("y")

return stack

def stackoperation_pop():

a=int(input("enter lement to pop"))

stack.pop(a)

print(stack)

return stack

def main():

print("entering to main")

while(1):

a=int(input("enter your operation choice\n 1.push\n 2.pop\n"))

if(a==1):

value=stackoperation_push()

print(value)

elif(a==2):

value= stackoperation_pop()

print(value)

else:

sys.exit()

if __name__=='__main__':

main()

"""

"""*************************finding intersection*********************

def intersection(lst1, lst2):

return set(lst1).intersection(lst2)

lst1 = [1,3,6,78,35,55]

lst2 = [12,24,35,24,88,120,155]

print(intersection(lst1, lst2))

"""

"""************************remove duplicate in list*************************/

lst = [12,24,35,24,88,120,155,88,120,155]

list=[]

for i in lst:

if i not in list:

list.append(i)

print(list)

"""

"""**************************Using Dictionary**************************"""

"""

thisdict = {

"brand": "cyient",

"model": "manager",

"year": 1964

}

print("before change: "+str(thisdict))

thisdict["year"]=2019

print("after change: "+str(thisdict))

"""

"""*********************exception hNDLING*****************"""

"""

x="hello"

assert x == "hello"

assert x == "goodbye"

"""

"""

try:

print(x)

except NameError:

print("Variable x is not defined")

except:

print("Something else went wrong")

"""

"""********************file handling************************

f = open("brajesh.txt", "a")

f.write("welcome to file that have some content")

f.close()

f = open("brajesh.txt", "r")

print(f.read())

"""

""" ********* write a program to generate all sentences where subject is in ["i","you"]

and verb is in ["play","love"] and the object is in ["hockey,"football"]*******"""

"""

list1=["i","you"]

list2=["play","love"]

list3=["hockey","football"]

for i in list1:

for j in list2:

for k in list3:

print(i+""+j+""+k)

"""

""" ******write a prog to print the list after removing even numbers in[5,6,77,45,22,12,24]

can u use lambda function"""

"""

lst1=[5,6,77,45,22,12,24]

list=[]

for i in lst1:

if (i%2==0):

list.append(i)

print(list)

"""

"""

lst1=[5,6,77,45,22,12,24]

even_nos = list(filter(lambda x: (x % 2 == 0), lst1))

print("Even numbers in the list: ", even_nos)

"""

"""************concept of module************************************************

import push1

import sys

def main():

print("entering to main")

while(1):

a=int(input("enter your operation choice\n 1.push\n 2.pop\n 3.Exit From here"))

if(a==1):

value=push1.stackoperation_push()

print(value)

elif(a==2):

value= push1.stackoperation_pop()

print(value)

else:

sys.exit()

if __name__=='__main__':

main()

"""

"""********* generate no between 1 and 9 and ask the user to

guess the no then tell whether they guessed too llow ,high or exactly right************************"""

"""

import random

import sys

def main():

b=random.randint(1,9)

while(1):

a= int(input("enter no to guess between 1 and 9: "))

if(a>b):

print("your no is high: ")

elif(a<b):

print("your no is low: ")

elif(a==b):

print("you guessed corect no.")

sys.exit

if __name__=='__main__':

main()

"""

"""********************* write aprogram that takes list of no. a=[5,10,15,20,25] and

makes a new list of only first and last elements of given list ************"""

"""

a= [5, 10, 15, 20, 25]

def listend(x):

return [x[0], x[4]]

print(listend(a))

"""

"""**************WAP to ask the number and deter,mine whether it is prime or not*************"""

"""

num= int(input("enter nmber to check prime: "))

if(num==4):

print(num, "is not prime")

if num > 1:

for i in range(2, (num//2)):

if (num % i) == 0:

print(num,"is not a prime number")

break

else:

print(num, "is a prime number")

"""

"""*************matrix multiplication**************************"""

"""X = [[12,7],

[4 ,5]]

Y = [[12,7],

[4 ,5]]

result = [[0,0],

[0 ,0]]

for i in range(len(X)):

for j in range(len(Y[0])):

for k in range(len(Y)):

result[i][j] += X[i][k] * Y[k][j]

for r in result:

print(r)

"""

"""************print patterns*******************

1

22

333

4444

"""

"""

n = 5

for i in range(1, n):

for j in range(1, i+1):

print(i ,end="")

print("\r")

"""

"""*************** 1.The hangman progran randomly selects a secret word from a list of secret words

.The random module will provide this ability so line 1 in program imports it

2.The game here a random word (fruit name )is picked up from our collection and the player gets limitd chances to win the game

3.when a letter in that word is guessed correctly that letter position in the word is made visible.In this way,

all letter of word are to be guessed before all the chances are over.

4FOr convenience we have given length of word +2 chances .For example word to be guessed is mango ,

then user gets 5+2=7 chances as mango is five letter word.

***************************************************************************************************************"""

import random

fruitname = ['apple', 'orange', 'mango', 'peach', 'guava']

wordsToGuess = ""

activeGuess = list()

guesses = list()

lives = 7

print("Hint: enter fruitname start from letter 'a' 'o' 'm' 'p' 'g'" )

a=input("enter any fruitnmae")

wordsToGuess = random.choice(fruitname)

for i in range(len(wordsToGuess)):

print("word is "+str(wordsToGuess))

activeGuess.append("_")

while lives > 0 and ("_" in activeGuess):

print("You have", lives, "guesses")

print(activeGuess)

guess = input("Please enter your guess: ")

while guess in guesses:

print("invalid input")

guess = input("Please enter your guess: ")

guesses.append(guess)

if(guess in wordsToGuess):

for i in range(len(wordsToGuess)):

if(guess == wordsToGuess[i]):

activeGuess[i] = guess

else:

lives -=1

if lives > 0 and lives <7:

print("your find correct before your live gone finished\n" , activeGuess)

print(activeGuess)

elif lives == 7:

print("*your guess is correct *\n" , activeGuess)

print(activeGuess)

else:

print("Try Again!\n" , activeGuess)

Informationen

Beschreibung
CTET Engineering Notiz am PYTHON SAMPLE PROGRAMS, erstellt von sneha singh am 25/04/2019.
Erstellt von
sneha singh · Apr 2019
Aktualisiert
25 Apr 2019
Aufrufe
3
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck