Hell O'
So from today I am gonna start a new blog series i.e. Coding. Here I am going to learn Python with all of you guys. I am basically writing a program daily and you can learn with me too. If you have any doubt, just drop it in the comment section and I will try to solve it.
My first program would be a little too simple and too easy for all, for that you don't need to install any IDE or any software, just google online python compiler and get started with the new interface and let's get started.
So 1st program, to find sum up to n number.
First, what we know, so there we can use either for loop or a direct formula to calculate the sum.
Secondly, which will get low space and time complexity, that also depend. But coz it's first program, we are gonna run both.
Now, the Program.
a = int(input("Enter any Number : "))
Sum = a * (a + 1) / 2
x = 0
for i in range(0, a+1):
x = x + i
print(x)
Since the output of the program is same, we can say they are one piece in a pot, but the time taken by each program to give answer really depends. Like the simple one line sum can give answers in less time than the second one. Hence the higher preference is given to the sum one.
When you are trying this program, just try to sum up to greater numbers like "1002402516" or any big number then you can get the feeling what I wanna say.
So for today, this is it, I will be coming back with another great code, till then Good bye.
BE YOURSELF
Recent Posts
See AllMy last blogg about gaming from your android, or my other blogs, that I published earlier were not a big hit, not like this website or...
Comments