This page contains all Python source code collection that we have posted for beginners to learn python programming in a simple and easy way.
1 2 3 4 5 6 7 8 | num1 = input('Enter first number: ') num2 = input('Enter second number: ') #Perform add operation sum = float(num1) + float(num2) #Print the output print('The sum of {0} and {1} is: {2}'.format(num1, num2, sum)) |
1 2 3 4 5 6 7 8 | num1 = input('Enter first number: ') num2 = input('Enter second number: ') #Perform multiplication operation sum = float(num1) * float(num2) #Print the output print('The multiplication of {0} and {1} is: {2}'.format(num1, num2, sum)) |
1 2 3 4 5 6 7 8 9 10 | n=int(input("Enter the number: ")) rev=0 while(n>0): dig=n%10 rev=rev*10+dig n=n//10 print("The reversed number is:", rev) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | n=int(input("Enter a number: ")) temp=n rev=0 while(n>0): dig=n%10 rev=rev*10+dig n=n//10 if(temp==rev) { print("The number is a palindrome!") }else { print("The number isn't a palindrome!") } |
1 2 3 4 5 6 7 8 9 10 | year=int(input("Enter year to be checked:")) if(year%4==0 and year%100!=0 or year%400==0) { print("The year is a leap year!) } else { print("The year isn't a leap year!) } |
1 2 3 4 5 6 7 8 9 10 | num = int(input("Enter a number: ")) factorial = 1 if num < 0: print("Sorry, factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1,num + 1): factorial = factorial*i print("The factorial of",num,"is",factorial) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | num = int(input("Enter a number: ")) if num > 1: for i in range(2,num): if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number") else: print(num,"is not a prime number") |
1 2 3 4 5 6 7 8 | num1 = input('Enter first number: ') num2 = input('Enter second number: ') #Perform division operation sum = float(num1) / float(num2) #Print the output print('The division of {0} and {1} is: {2}'.format(num1, num2, sum)) |
Find more Python code examples? click the below link.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.