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

Python.

The document contains various Python and Arduino code snippets for performing mathematical operations, checking properties of numbers (like Armstrong, palindrome, prime), and interfacing with hardware components. It includes functionality for calculating factorials, generating Fibonacci series, replacing characters in strings, and handling arrays. Additionally, it provides examples of using LCD displays and sensors in Arduino programming.
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)
0 views11 pages

Python.

The document contains various Python and Arduino code snippets for performing mathematical operations, checking properties of numbers (like Armstrong, palindrome, prime), and interfacing with hardware components. It includes functionality for calculating factorials, generating Fibonacci series, replacing characters in strings, and handling arrays. Additionally, it provides examples of using LCD displays and sensors in Arduino programming.
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

# number is armstrong or not # no is palindrome or not

a=int(input()) a=int(input())

c=a c=a

b=0 b=0

while(a>0): while(a>0):

b=b+((a%10)**3) b=(b*10)+(a%10)

a=a//10 a=a//10

if(b==c): if(b==c):

print("armstrong") print("palindrome")

else: else:

print("not armstrong") print("not palindrome")

print("---------------------------------------------") print(".............................................")

3)# armstrong from 100 to 400 4)#palinrome from 100 to 200


print("armstrong from 100 to 1000") print("palindrome from 100 to 200")

for i in range(100,1001): for i in range(100,201):

c=i c=i

b=0 b=0

while(i>0): while(i>0):

b=b+((i%10)**3) b=(b*10)+(i%10)

i=i//10 i=i//10

if(b==c): if(b==c):

print(b) print(b)

print("-----------------------------------") print(".............................................")
# no. is prime or not #factor of a no.
a=int(input()) a=int(input())

f=0 print("factorr of",a)

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

if(a%i==0): if(a%i==0):

f=f+1 print(i)

if(f==2): print(".............................")

print("prime no.") #factors of no. from 1 to 5


else: for i in range(1,6):
print("not prime") print("factor of",i)
print(".............................................") for j in range(1,i+1):

#prime no from 1 to 25 if(i%j==0):

print("prime no from 1 to 25") print(j)

for i in range(1,26): print(".............................")

f=0

for j in range(1,i+1):
#replacing a with n and b with k
if(i%j==0):
a=input()
f=f+1
ns=""
if(f==2):
for i in a:
print(i)
if(i=='a'):

ns=ns+'n'

elif(i=='b'):

ns=ns+'k'

else:

ns=ns+i

print(ns)
# factorial of a number
a=int(input()) #sum of n natural no.
print("factorial of",a) n=int(input())

f=1 print("natural numbers till",n)

for i in range(1,a+1): for i in range(1,n+1):

f=f*i print(i)

print(f) print(".........................")

print("...............................") s=0

#factorial of no from 1 to 5 for i in range(1,n+1):

for i in range(1,6): s=s+i

print("factorial of",i) print("sum of numbers till",n)

m=1 print(s)

for j in range(1,i+1): print("odd numbers till",n)

m=m*j for i in range(1,n+1):

print(m) if(i%2!=0):

print("..............................") print(i)

print("........................")

print("sum of odd no till",n)


#replacing vowel with $
so=0
a=input()
for i in range(1,n+1):
ns=""
if(i%2!=0):
vow=['a','A','e','E','i','I','o','O','u','U']
so=so+i
for i in a:
print(so)
if(i in vow):

ns=ns+"$"

else:

ns=ns+i

print(ns)
#replacing a with b , b with c , d with # list ka max, min, avg, sorted karna
e, z with a
a=[]
a=input()
for i in range(5):
ns=''
[Link](int(input()))
for i in a:
print(a)
if(i=='z'):
l=len(a)
ns=ns+'a'
[Link]()
elif(i=='z'):
print("sorted list")
ns=ns+'A'
print(a)
else:
print("greatest element")
ns=ns+chr(ord(i)+1)
print(max(a))
print(ns)
print("smallest element")

print(min(a))

# find gcd and lcm of no. print("2nd largest")

import math print(a[l-2])

a=int(input()) print("2nd smallest")

b=int(input()) print(a[1])

print("gcd of these no.") print("sum of the element")

gcd=[Link](a,b) print(sum(a))

print(gcd) print("average of the element of the list")

lcm=a*b/gcd print(sum(a)/l)

print("lcm of these no.") # print 1/2, 1/3, 1/4, 1/5


print(lcm) print("enter the limit")

n=int(input())

for i in range(2,n+1):

print("1/",i,"is",1/i)
#elements which are divisible by 2 # product of 2 no. using lambda fun
and 3 both
a=lambda x,y:x*y
a=[]
m=int(input())
for i in range(5):
n=int(input())
[Link](int(input()))
print(a(m,n))
b=[]
# replace name by another name
for i in a:
a=input()
if(i%2==0 and i%3==0):
b=[Link]()
[Link](i)
ch=input()
print(b)
rch=input()

c=[]

# duplicate alphabet remove karna for i in b:

# same latter repeat nhi hoge if(i==ch):

print("enter the string") [Link](rch)

a=input() else:

ns="" [Link](i)

for i in a: print(" ".join(c))

if(i not in ns): if(ch not in a):

ns=ns+i print(ch,"is not in the message")

print(ns) or
# fun ka use karke do digit ka multiplication a=input()

b=[Link]()
def abc(a,b):
c=[]

return a*b for i in b:

a=int(input()) if(i=="is"):

[Link]("are")
b=int(input())
else:

print(abc(a,b)) [Link](i)

print(" ".join(c))
# Fibonacci series #mean of the values of dictonary
n=int(input("Enter the number")) a={}

a=0 for i in range(3):

b=1 a[int(input())]=int(input())

print("Fibonacci series:") s=0

print(a) for i in [Link]():

print(b) s=s+i

for i in range(n): print(a)

a,b=b,a+b print("mean")

print(b) print(s/3)

# repeated value print karna #commulative sum of list's element


a=[] a=[10,20,30,40,50]

for i in range(6): b=[]

[Link](int(input())) s=0

b=[] for i in a:

for i in a: s=s+i

for j in range([Link](i)+1,len(a)): [Link](s)

if(i==a[j] and i not in b): print(b)

[Link](i) #print yes if number isdivisible by another


number
print(b)
a=int(input())
upar se niche digit increase karna
b=int(input())
for i in range(1,5):
def abc(a,b):
for j in range(1,i+1):
if(a%b==0 or b%a==0):
print(j,end=" ")
print("Yes")
print()
else:

print("No")

abc(a,b)
#print found if there is common elemenet #marks in subject and toper
in both lists
s1=[]
a=[] s2=[]
for i in range(3): s3=[]
[Link](int(input())) for i in range(5):
b=[] print("marks in sub",i+1)
for i in range(3): [Link](int(input()))
[Link](int(input())) [Link](int(input()))
c="not found" [Link](int(input()))
for i in a: p1=sum(s1)*100/500
for j in b: p2=sum(s2)*100/500
if i==j: p3=sum(s3)*100/500
c="found" print("Ram",p1)
print(c) print("Shyam",p2)
#vowel change nhi hoge consonant change print("Gopal",p3)
hoge
if(p1>p2 and p1>p3):
a=input()
print("Ram is toper")
ns=""
elif(p2>p1 and p2>p3):
v=['a','A','e','E','i','I','o','O','u','U']
print("Shyam is toper")
for i in a:
elif(p3>p1 and p3>p2):
if(i in v):

ns=ns+i print("Gopal is toper")

elif(i=='z'): else:

ns=ns+'a' print("equal")

elif(i=='Z'):

ns=ns+'A'

else:

ns=ns+chr(ord(i)+1)

print(ns)
# print table using recursion

a=int(input())

def abc(n):

if n>10:

return False

else:

print(n*a)

abc(n+1)

abc(1)

# print numbers using recursion

def abc(n):

if n>10:

return False

else:

print(n)

abc(n+1)

abc(1)

# intersection of two arrays

import numpy as np

a=[Link]([12,15,7,9,7])

b=[Link]([45,12,65,34,9])

c=[]

for i in a:

for j in b:

if(i==j):

[Link](i)

d=[Link](c)

print(d)
// WAP to print table of a no. on lcd. // write to blink 4 lead alternativaly

#include<LiquidCrystal.h> int a=5;

LiquidCrystal lcd(13,12,11,10,9,8); int b=6;

int a=20; int c=7;

void setup(){ int d=8;

[Link](16,2); void setup(){

for(int i=1; i<=10; i++){ pinMode(a,OUTPUT);

[Link](i*a); pinMode(b,OUTPUT);

[Link](" "); pinMode(c,OUTPUT);

} pinMode(d,OUTPUT);

} }

void loop(){ } void loop(){

digitalWrite(a,HIGH);

delay(1000);

digitalWrite(a,LOW);

delay(1000);

digitalWrite(b,HIGH);

delay(1000);

digitalWrite(b,LOW);

delay(1000);

digitalWrite(c,HIGH);

delay(1000);

digitalWrite(c,LOW);

delay(1000);

digitalWrite(d,HIGH);

delay(1000);

digitalWrite(d,LOW);

delay(1000);}
// WAP to interface any device. // WAP to interface led with push button.

#include<LiquidCrystal.h> int bt=5;

LiquidCrystal lcd(13,12,11,10,9,8); int led=7;

int a=A1; void setup(){

int b=5; pinMode(bt,INPUT);

void setup(){ pinMode(led,OUTPUT);

pinMode(a,INPUT); int st=digitalRead(bt);

pinMode(b,OUTPUT); if(bt==HIGH){

int c=analogRead(a); digitalWrite(led,HIGH);

[Link](16,2); delay(100);

if(c==HIGH){ }

[Link]("Activated"); else{

[Link](c); digitalWrite(led,LOW);

digitalWrite(b,HIGH); delay(100);

delay(100); }}

} void loop(){

else{ }

[Link]("Deactivated");

[Link](c);

digitalWrite(b,LOW);

delay(100);

}}

void loop(){

[Link]();

delay(100);

}
// wap to interface any sensor // WAP to interface led/buzzer/speaker.

#include<LiquidCrystal.h> int a=5;

LiquidCrystal lcd(13,12,11,10,9,8); void setup(){

int gassensor=A2; pinMode(a,OUTPUT);

int led=5; }

void setup(){ void loop(){

pinMode(gassensor,INPUT); digitalWrite(a,HIGH);

pinMode(led,OUTPUT); delay(1000);

int a=analogRead(gassensor); digitalWrite(a,LOW);

if(a>0){ delay(1000);

[Link](16,2); }

[Link]("Activated");

[Link](a);

digitalWrite(led,HIGH);

delay(100);}

else{

[Link](16,2);

[Link]("Deactivated");

[Link](a);

digitalWrite(led,LOW);

delay(100);

}}

void loop(){

[Link]();

delay(100);

You might also like