Posts

Showing posts with the label Interesting codes in python

Program to create a four function calculator

 num1 = float(input("Enter first number:")) num2 = float(input("Enter second number:")) a = num1 + num2 p = num1 * num2 s = num1 - num2 d = num1 / num2 print("sum of num1 and num2 is", a) print("product of num1 and num2 is", p) print("subtraction of num1 and num2 is" , s) print("division of num1 and num2 is" , d) ☝☺

How to add comments in python ?

 Comments Comments are used to add a remark or a note in the  source code. Comments are not executed by interpreter.They are added with the purpose of making the source  code easier for humans to understand. They are used  primarily to document the meaning and purpose of  source code and its input and output requirements,  so that we can remember later how it functions and  how to use it. For large and complex software, it may  require programmers to work in teams and sometimes,  a program written by one programmer is required to be  used or maintained by another programmer. In such  situations, documentations in the form of comments  are needed to understand the working of the program. Write a Python program to find the sum of  two numbers. #Program 5-4 #To find the sum of two numbers num1 = 10 num2 = 20 result = num1 + num2 print(result)  Output: 30

How to create a list in Python

 List  List is a sequence of items separated by commas and  the items are enclosed in square brackets [ ]. #To create a list list1 = [5,3.4,"New Delhi","20C", 45] #print the elements of list1 print(list1)

How to create a set in python

Set Set is an unordered collection of items separated by commas  and the items are enclosed in curly brackets { }. A set is  similar to list, except that it cannot have duplicate entries.  Once created, elements of a set cannot be changed. Run this code in python or online python compiler to create a set #Create set set1 = {10,20,30,40,50} #print the elements of set 1 print (set1)