DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

python session day 2 at payilagam

To know whether there is PYTHON programming language in our linux machine.

Just open the terminal and type python3 automatically it shows the version of the python what you are using and it opens the python language in the terminal also.

We can't create any application in Day 1. But we can do it in python.
Simply we can do operation in the terminal like.


>> 10+12
>> 22
>> 10*3
>> 30
>> 35/7
>> 5.0
>> 45-10
>> 35
Enter fullscreen mode Exit fullscreen mode

like that....

to exit python from the terminal
just type exit() command in the terminal.

To copy anything in the terminal press ctrl+shift+c

to write the program open text editor in the linux

go to edit and select preferences select your own look

MY FIRST PROGRAM :

name = input("what is your name?")
print("Welcome to Python, name)


output:
What is your name ? RAJA
Welcome to python RAJA
Enter fullscreen mode Exit fullscreen mode

after typing the program in the editor press ctrl+s save the copy in the desktop .

to open desktop press ctrl+D
press right click to open the terminal
type python3 and type your saved document
it shows the output

FUNCTIONS:
What is FUNCTIONS :
Set of instructions for achieving a specific task.

Example:
Watching_Meiyazhagan:
1) laptop_on
2) Netflix
3) Meiyazhagan
4) Play

If seen in brackets it is function

input() is a function
print() is a function
Mainly these are all pre-defined function.

Function can be performed without arguments also

#python# means comment python will not take that as code.

using pre-defined function

no1 = 100
no2 = 5
print(no1+no2)
print(no1-no2)
print(no1*no2)
print(no1/no2)

output :
105
95
500
20.0
Enter fullscreen mode Exit fullscreen mode

user - defined function mainly used as code reusablity.

def add (Should be meaningful (if space required use it like sleeping_bed)

USING USER-DEFINED FUNCTION:

def calculate(no1, no2)
    print(no1+no2)
    print(no1-no2)
    print(no1*no2)
    print(no1/no2)

no1 = 100
no2 = 5
calculate(no1, no2)
Enter fullscreen mode Exit fullscreen mode
output:
105
95
500
20.0
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
payilagam_135383b867ea296 profile image
Payilagam

to open desktop press ctrl+D --> should be Start Button + D