embedded system,Arduino,Raspberry pi,ARM7,MM32,STM32,PIC and Python,Django,Datascience and web development
Monday, March 23, 2020
even or odd using python language
list_of_numbers=[1,2,3,4,5,6]
for number in list_of_numbers:
if number%2==0:
print(number,"is even")
else :
print(number,"is odd")
print("end of the code")
output:
for number in list_of_numbers:
if number%2==0:
print(number,"is even")
else :
print(number,"is odd")
print("end of the code")
output:
1 is odd 2 is even 3 is odd 4 is even 5 is odd 6 is even end of the code
tuple in python
n=input("enter a comma separated number:")
l=n.split(",")
t=tuple(l)
print("l=",l,"t=",t)
print(type(l),"\n",type(t))
output:
enter a comma separated number:2,3,4,5
l= ['2', '3', '4', '5'] t= ('2', '3', '4', '5')
<class 'list'>
<class 'tuple'>
l=n.split(",")
t=tuple(l)
print("l=",l,"t=",t)
print(type(l),"\n",type(t))
output:
enter a comma separated number:2,3,4,5
l= ['2', '3', '4', '5'] t= ('2', '3', '4', '5')
<class 'list'>
<class 'tuple'>
dictionary in python
n=int(input("enter a number:"))
d=dict()
for i in range(1,n+1):
#print("i=",i)
d[i]=i*i
print(d)
output:
enter a number:5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
d=dict()
for i in range(1,n+1):
#print("i=",i)
d[i]=i*i
print(d)
output:
enter a number:5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Subscribe to:
Posts (Atom)
-
How to do the programming python in windows command prompt Step 1: please go through below link website f...
-
Serial.print() Description Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers a...