Basic Program - Python Programming Language

Program 1:

print("For print a massage")
print("Hello Python!")

Output:

For print a massage
Hello Python!

Program 2:

print("For addition of two number")
a = 10 
b = 20     
sum = a+b
print("Sum of two number is ",+sum)

Output:

For addition of two number
Sum of two number is 30

Program 3:

print("For addition of two number by user input")
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
sum = int(a+b)
print("Addition of two number is ",+sum)

Output:

For addition of two number by user input
Enter a number: 30
Enter another number: 20
Sum of two number is 50

Program 4:

print("For subtraction of two number by user input")
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
sub = int(a-b)
print("Subtraction of two number is ",+sub)

Output:

For subtraction of two number by user input
Enter a number: 30
Enter another number: 20
Subtraction of two number is 10

Program 5:

print("For multiplication of two number by user input")
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
mul = int(a*b)
print("Multiplication of two number is ",+mul)

Output:

For multiplication of two number by user input
Enter a number: 30
Enter another number: 20
Multiplication of two number is 600

Program 6:

print("For division of two number by user input")
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
div = float(a*b)
print(" Division of two number is ",+div)

Output:

For division of two number by input
Enter a number: 30
Enter another number: 20
Division of two number is 1.5

Program:

print("For swap two variable value with extra variable")
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
c = a
a = b
b = c
print("After Swapping")
print("Value of a = ",+a)
print("Value of b = ",+b)

Output:

For swap two variable value with extra variable
Enter the value of a: 20
Enter the value of b: 30
After Swapping
Value of a = 30
Value of b = 20

Discussion

Read Community Guidelines
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.