Tuesday, October 22, 2019

Learning python Day 7


Day7
Functions
Two types of function: library and user defined functions
To define function we use def
def disp():
   
print("Hello")

print("Started")
disp()  
#function calling
print("Back")
run the function CTL+shift+fn+F10
Started
Hello
Back
def findsum(x,y):
   
print("Sum=",x+y)


a=
int(input("Enter a number "))   #5
b=int(input("Enter 2nd number "))   #7
findsum(a,b)

findsum(
10,20)
findsum(
100,20)
run the function CTL+shift+fn+F10
Enter a number 7
Enter 2nd number 5
Sum= 12
Sum= 30
Sum= 120
def findsum(x,y):
   
return x+y

a=
int(input("Enter a number "))   #5
b=int(input("Enter 2nd number "))   #7
c=findsum(a,b)
print("Sum=",c)
run the function CTL+shift+fn+F10
Enter a number 7
Enter 2nd number 5
Sum= 12
def disp(n):
   
if(n%2==0):
       
print(n,"is even")
   
else:
       
print(n,"is odd")

a=
int(input("Enter a number"))
disp(a)
disp(
34)
disp(
98)
run the function CTL+shift+fn+F10
Enter a number7
7 is odd
34 is even
98 is even
def findlargest(a,b,c):
   
if(a>b and a>c):
       
print(a,'is largest')
   
elif(b>a and b>c):
       
print(b,'is largest')
   
elif(c>a and c>b):
       
print(c,'is largest')
   
else:
       
print("Can't find the largest one")


findlargest(
12,54,23)
run the function CTL+shift+fn+F10
54 is largest
def table(n):
   
print("Table of",n,"is")
   
for i in range(1,11):
       
print(n*i)

a=
int(input("Enter a number"))
table(a)
table(
9)
run the function CTL+shift+fn+F10

Enter a number7
Table of 7 is
7
14
21
28
35
42
49
56
63
70
Table of 9 is
9
18
27
36
45
54
63
72
81
90


Learning Python - Day 8

No comments:

Post a Comment

Featured Post

Ichimoku cloud

Here how you read a ichimoku cloud 1) Blue Converse line: It measures short term trend. it also shows minor support or resistance. Its ve...