Posts

Write a python program to check if it is an odd or even number using if condition.

Image
 As we all know, every number which is divisible by 2 we call it as even and the number which is not divisible by 2 we call it as odd. In Python, we have an Arithmetic Operator called % (Modulus) to see the remainder. We will use it to find out whether a number is odd or even. Code: a= int(input("Enter a number:")) if a%2==0:     print("Entered number is an even number") else:     print("Entered number is an odd number") Output: First, let's check with an odd number: Enter a number:55 Entered number is an odd number   Now, with an even number: Enter a number:20 Entered number is an even number    

Write a program to input two numbers and inter change their values in python IDLE.

Image
Number swapping in python can be done in multiple ways. For example, using a third or temporary variable, using arithmetic operators etc.  In this tutorial, we will use the third or temporary variable.  Make two variable and one temporary variable to take input two numbers from the user and store one number in the temporary variable.   For example: first number, second number and temporary, or simple a, b and temp.    Code: a=int(input("Enter the first number:")) b=int(input("Enter the second number:")) print("Before swapping the two numbers first:{0} and second:{1}".format(a,b)) temp= a a= b b= temp print("After swapping the two numbers frist:{0} and second:{1}".format( a, b)) Output: Enter the first number:15 Enter the second number:20 Before swapping the two numbers first:15 and second:20 After swapping the two numbers frist:20 and second:15