This content originally appeared on DEV Community and was authored by Natnael Getenew
In my humble opinion learning, by comparison, is the best way of learning, To stay in the loop while the industry is moving extremely rapidly, learning complex concepts by comparing to already familiar stuff is our best bet.
In this blog post, I will show you some common programs implemented in python and C++, So if you are trying to learn one of those languages or both at the same time! this post will serve you to learn in a comparable manner, let's dive in!
Hello World Program
- Hello World Program in python
print("Hello, World!")
- Hello World Program in C++
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
Display Fibonacci Series
- Display Fibonacci Series in python
nterms = int(input("How many terms you want? "))
# first two terms
n1 = 0
n2 = 1
count = 2
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence:")
print(n1)
else:
print("Fibonacci sequence:")
print(n1,",",n2,end=', ')
while count < nterms:
nth = n1 + n2
print(nth,end=' , ')
# update values
n1 = n2
n2 = nth
count += 1
}
- Display Fibonacci Series in C++
#include <iostream>
using namespace std;
int main() {
int n1=0,n2=1,n3,i,number;
cout<<"Enter the number of elements: ";
cin>>number;
cout<<n1<<" "<<n2<<" "; //printing 0 and 1
for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
cout<<n3<<" ";
n1=n2;
n2=n3;
}
return 0;
}
weather If you already know cpp and trying to learn python or vice-versa I hope you get the general gist of the Syntax difference between the two languages,
If you like this and this method of learning things, I have a repository dedicated to comparing programming languages and concepts, you can check it out on github
This content originally appeared on DEV Community and was authored by Natnael Getenew
Natnael Getenew | Sciencx (2021-03-12T09:34:14+00:00) C++ Vs Python Syntax Difference. Retrieved from https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.