MINI CALCULATOR:
print("simple calculator")
a = float(input("enter first number: "))
b = float(input("enter second number: "))
op = input("choose operation (+,-,*,/)
if op == '+':
print("result:" , a + b)
elif op == '-':
print("result:" , a - b)
elif op == '*':
print("result:" , a * b)
elif op == '/':
print("result:" , round(a / b,2))
else:
print("Invalid operation")
LENGTH CHECKER:
name = input("Enter your name: ")
print("your name has" , len(name), "character"
PASSWORD LENGTH CHECK:
name = intput("enter your password: ")
password = len(name)
if password <=8:
print("your password is short")
if password >=10:
print("your password is long")
if password == 9:
print("your password is valid")
RETURN STATEMENTS:
A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function. For more information, see Return type.
def chitchat();
print("chatting with friends:)
def withdraw():
print("entering",pin)
return 500
def watch():
return CSk
chitchat()
purse = withdraw(1234)
print(purse)
def calculate_amount(unit):
if unit<100:
print('FREE')
elif unit<200:
print(unit*1,20)
elif unit<300:
print(unit*2)
consumed_units = eb_reading()
calculate_amount(consumed_units)
In python everything is an object.
In python every python is a module.
code reusability, Documentation string, name of file.
import calc2
calc2.add(123,321)
print(calc2.__doc__)
print(dir(calc2))
print(calc2.__name__)
print(calc2.__file__)
print(calc2.__spec__)
print(calc2.package)
OTP GENERATOR:
import random:
print (random.__doc__)
print(dir(random))
print(round(round.random(),2)*100)
print(dir(random))
print(random.randint(100000,10000000)
import sys
print(sys.argv)
print(sys.__doc__)
python3 user.py mathan salman kuhan
print(sys.argv[1])
import sys
print(sys.path)
print(type(sys.path))
sys.path.append('folder')
import calc2
calc2.add(10,20)
OS MODULE:
import os
print(os.getcwd())
os.mkdir("abcd")
os.chdir('home/muthu/documents/B10')
os.rmdir('home/muthu/documents/abcd')
print(os.listdir('home/muthu/Documents/B10)
os.makedirs('home/muthu/Documents/B10/Salman/mathan/kuhan')
os.removedirs('home/muthu/Documents/B10/Salman/mathan/kuhan')
os.rename('home/muthu/documents/abcd','home/muthu/documents/pqrs')
import os
print(os.__doc__)
print(os.utime('home/muthu/documents/B10/calc2.py')
print(help(os.time))
print(dir(os))
import os
print(os.path)
popen() --> function
import os
print(os.system("Python3 --version")
import os
print(os.listdir())
print(os.path.exists('home/muthu/documents/B10')
print(os.path.exists('os.py')
import os
print(os.path.getsize("calc.py"))
import os
print(os.cpucount())
print(os.getlogin())
SYS MODULE:
import sys
sys.version
sys.version_info
sys.stdout
sys.stdin
sys.floatinfo.
sys.intinfo
sys.copyright
import keyword
keyword.__doc__
keyword.kwlist
len(keyword.kwlist)
help('import')
help('False')
ESC + shift + : + q --> exiting one terminal
import sys
print(sys.executable)
print(sys.platform)