-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCH-7-PYTHON FUNCTION.py
52 lines (39 loc) · 1.39 KB
/
CH-7-PYTHON FUNCTION.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#functions!!
'''' retutrn none is nothing is returned
arguments-values,parameters-f() def
required,keyword,anonymous or lambda,recursive'''
#def keyword is used!!
''' a global varaible can't be accessed without pasing them into a block else use global <variable> keyword''' #WTF!!!!!!
'''n=int(input("enter a no:"))
def fact(n):
i=1
f=1
while(i<=n):
f=f*i
i=i+1
return f
a=fact(n)
print("the factorial of",n,"is",a)'''
#does not necesarily need to return....nothing returns resuts o/p as NONE!
#default arguments in function defenition!
#in keyword argument order of call doesn't matter!
# def he(*arg) VARIABLE LENGTH ARGUMRNT
#lambda <Lf() name>=lambda <arguments>:<expression>
a=float(input("enter a floating point number:"))
print("abs(a):",abs(a)) #sign change
a=int(input("enter a number:"))
print("chr(a):",chr(a)) #asci char
b=input("enter a letter:")
print("ord(b):",ord(b)) #asci val
print("bin(a):",bin(int(a))) #to bin
print("type(a):",type(a),"\nid(a):",id(a))
#min(),max(),sum() in a list!
print("d-b",format(a,'b')) #decimal to other conversion!
print("d-o",format(a,'o'))
print("d-o",format(a,'x'))
print("d-f",format(a,'f')) #decimal to FIXED POINT! 6prescision!
a=input("enter a f numebr:")
print("round(a)=",round(float(a)))
#pow()
#import math----> floor(),ceil(),sqrt()!!
#eval() --> evaluvates the expresssion or statment or the varaible!