techletter
techletter
Untitled
2 posts
Don't wanna be here? Send us removal request.
techletter · 4 years ago
Text
Basics of Python Programming
Getting started with Python is super easy. Even if you don’t have a programming background or you still can be a master in Python and that too in a very short span of time. The only thing needed here is just practice what you learn. The more you practice, the more you get to used to the language syntax and the better programmer you will be. 
Taking input in python is super easy:-
Tumblr media
Taking user input in an interactive way:-
Tumblr media
TAKING MULTIPLE USER INPUTS IN A SINGLE LINE:-
Like any other programming language, Python also provides the programmers with taking multiple user inputs in a single line without paying extra efforts to  "write more to take more". This is done using the  'split()'  method which splits the entered user input at the separator provided as an argument to split() method:   
SYNTAX:   input().split(separator)
Suppose that you have 4 variables a,b,c,d and you want take user input in a single line. You can do it in the following manner:     
a,b,c,d = input().split()
Done...
Now a question comes to your mind that we haven't provoded the separator to the split() method. How'd the split method split the user input?
The answer to this question is that when no parameter is passed as separator, the split() method by default assumes  ' space '   to be the separator.
Try this yourself on IDLE or try to use them in a program and see the outputs.
Tumblr media
Even/Odd Program in Python:-
Python is really an enjoyable language both for beginners as well as professionals. You can write an elegant code and that too in less LOC (Lines Of Code).See the below program where we need to display whether a number entered by user is Odd/Even.
Note: For simplicity, we assume that you are a beginner and the user is intelligent enough to enter only integers (non-zero). 
        ---Code:---
inp = int(input('Enter any integer: '))
print('Its an even no.' if inp % 2 == 0 else 'Its an odd no.')
         ---Output:---
(1)Enter any integer: 7
    Its an odd no.
(2)Enter any integer: 10
    Its an even no.
Tumblr media
SWAPPING in 'P Y T H O N':-
Unlike other programming languages where swapping needs a third variable or require us to do some arithmetic calculations, swapping(interchanging values between two variables) is far far more easier in Python. Its so easy that we can do it in only a single line of code. Suppose that we have 2 variables 'a' and 'b' with some value in them and we want to swap/interchange their values. We can do it in the following easy manner:
      a,b = b,a  
Done..
Check the below image for clear understanding.
Tumblr media
DIVISIBILITY TEST of two no.s in 'P Y T H O N' :
Divisibility test, as we all know, is a test to check whether a no. is perfectly divisible by another no. i.e., on dividing both the numbers whether the remainder is equal to 0. And this test can be done very easily in Python using the   '%' (modulo) operator. The modulo operator, like other arithmetic operators(+, - , *, /) is an operator which is used to get the REMAINDER of division between 2 numbers. Suppose we want to check whether 53 is divisible by 17 or not. All we need to do is just to write the modulo operator in between the 2 no.s and see the output on terminal as follows:          
>>>   53 % 17          
>>>   2      
As can be seen the remainder is not equal to 0. Hence the numbers do not pass the divisibility test. 
Try this test with other numbers yourself on IDLE or try to use them in a program and see the outputs.
Tumblr media
There are countless such examples which speak for the beauty of this language. I hope you people liked this post and will definitely try learning this awesome languuage.
0 notes
techletter · 4 years ago
Photo
Tumblr media Tumblr media Tumblr media Tumblr media
Place: Srinagar Spot Name: Dal Lake
1 note · View note