Posts

Showing posts from January, 2021

User int input in another way?

 Print ("Enter first number") num1=input () Print ("Enter second number") num2=input () print ("sum of two number is:",int(num1)+int(num2))

sum of two numbers without using int in python?

  print ("Enter first number")  f1 = input ()  print ("Enter second number")  f2 = input ()  print ("Sum of these two numbers is",   int(f1) + int(f2))  #Output of this program  Enter first number  21  Enter second number  8  Sum of these two numbers is 29

Python Program to find the square root of a number by Newton’s Method?

  Newton's Method to find Square root Let the given number be b and let x be a rough guess of the square root of b.  New x = 0.5 * (x + b/x) Program Code def newton_method(number, number_iters = 100):     a = float(number)      for i in range(number_iters):          number = 0.5 * (number + a / number)      return number a=int(input("Enter first number:")) b=int(input("Enter second number:")) print("Square root of first number:",newton_method(a)) print("Square root of second number:", newton_method(b)) Output Enter first number:81 Enter second number:5 Square root of first number: 9.0 Square root of second number: 2.23606797749979

Coding guidelines?

Image
  General coding guidelines provide the programmer with a set of the best methods which can be used to make programs more comfortable to read and maintain. Most of the examples use the C language syntax, but the guidelines can be tested to all languages. The following are some representative coding guidelines recommended by many software development organizations. 1. Line Length:  It is considered a good practice to keep the length of source code lines at or below 80 characters. Lines longer than this may not be visible properly on some terminals and tools. Some printers will truncate lines longer than 80 columns. 2. Spacing:  The appropriate use of spaces within a line of code can improve readability. Example: Bad:         cost=price+(price*sales_tax)                 fprintf(stdout ,"The total cost is %5.2f\n",cost); Better:       cost = price + ( price * sales_tax )                   fprintf (stdout,"The total cost is %5.2f\n",cost); 3. The code should be well-doc

Coding standards?

Image
  General coding standards refers to how the developer writes code, so here we will discuss some essential standards regardless of the programming language being used. The following are some representative coding standards: Indentation:  Proper and consistent indentation is essential in producing easy to read and maintainable programs. Indentation should be used to: Emphasize the body of a control structure such as a loop or a select statement. Emphasize the body of a conditional statement Emphasize a new scope block Inline comments:  Inline comments analyze the functioning of the subroutine, or key aspects of the algorithm shall be frequently used. Rules for limiting the use of global:  These rules file what types of data can be declared global and what cannot. Structured Programming:  Structured (or Modular) Programming methods shall be used. "GOTO" statements shall not be used as they lead to "spaghetti" code, which is hard to read and maintain, except as outline

Characteristics of programming language?

Image
Following are the characteristics of Programming Language: Readability:  A good high-level language will allow programs to be written in some methods that resemble a quite-English description of the underlying functions. The coding may be done in an essentially self-documenting way. Portability:  High-level languages, being virtually machine-independent, should be easy to develop portable software. Generality:  Most high-level languages allow the writing of a vast collection of programs, thus relieving the programmer of the need to develop into an expert in many diverse languages. Brevity:  Language should have the ability to implement the algorithm with less amount of code. Programs mean in high-level languages are often significantly shorter than their low-level equivalents. Error checking:  A programmer is likely to make many errors in the development of a computer program. Many high-level languages invoke a lot of bugs checking both at compile-time and run-time. Cost:  The ultimate

Goals of coding?

  To translate the design of system into a computer language format:  The coding is the process of transforming the design of a system into a computer language format, which can be executed by a computer and that perform tasks as specified by the design of operation during the design phase. To reduce the cost of later phases:  The cost of testing and maintenance can be significantly reduced with efficient coding. Making the program more readable:  Program should be easy to read and understand. It increases code understanding having readability and understandability as a clear objective of the coding activity can itself help in producing more maintainable software. For implementing our design into code, we require a high-level functional language. A programming language should have the following characteristics:

What is coding?

  The coding is the process of transforming the design of a system into a computer language format. This coding phase of software development is concerned with software translating design specification into the source code. It is necessary to write source code & internal documentation so that conformance of the code to its specification can be easily verified. Coding is done by the coder or programmers who are independent people than the designer. The goal is not to reduce the effort and cost of the coding phase, but to cut to the cost of a later stage. The cost of testing and maintenance can be significantly reduced with efficient coding.

Computer programming languages?

There are following multiple programming languages that allow programmers to process and execute small as well as large programs: C Language:  The language was developed in  1972  by  Dennis Ritchie  and its laboratories at  AT & T Bells  It was basically designed and developed for implementing the UNIX OS. It is a structured programming language. C++:  It was developed in  1983  and was an object-oriented version of the C programming language. C++ was developed for providing high-level abstractions so as to handle large development projects efficiently. C#:  It was developed in  1983 , known as  Objective-C  by  Apple . It was mainly created for addressing the lacking points of the object-oriented programming language. Later on, it was licensed by  NeXt  in  1988 . Python:  It was developed in the late 1980s, which was an advanced programming language because it was object-oriented, interpreted, robust plus flexible. Java:  It was developed in  1990  at  Sun Microsystems , and was

programming language?

 1206: Al-Jazari, an Arab engineer, invented a programmable drum machine that was able to play several drum patterns and rhythms through pegs and cams.  Such a drum machine was a musical mechanical automaton.   1801: The Jacquard loom that was invented by Joseph Marie Jacquard (a French weaver) was able to produce different weaves by changing the 'program'.   In the 9th century, various code-breaking algorithms were also introduced.  An Arab mathematician Al-Kindi gave rise to an algorithm that was able to decipher the encrypted code.  The algorithm was known as the Cryptographic algorithm.   1843: Ada Lovelace, a mathematician, published an algorithm for calculating a sequence of Bernoulli numbers.  The algorithm was carried out by the Analytical Engine that was given by Charles Babbage.  It was the year when the first computer program was dated.   1880: Herman Hollerith, an American inventor, invented the idea and concept to store data in machine-readable form.  Later, a cont

Concept of computer programming?

 Every learning has some basic concepts that should be understood thoroughly.  A person can be good at mathematics if the basic concepts are clear to study maths at higher levels, in English, one should be clear with English grammar so that they can speak, write and communicate very well in English.  So, to move to a higher level, one should be clear with their basic level of knowledge.  There are the following concepts in computer programming that should be clear for learning and hands-on in computer programming:   We should know about the programming environment.   The grammar of computer programming, known as Syntax.   Role of data types, variables, and keywords in computer programming.   Different types of loops and its role in computer programming   What are input and output operations in computer programming   Functions and its role   Various types of logical and arithmetic operators.   To become a good computer programmer and enhance your knowledge level in computer programming,

What is computer programming?

 As human beings use different languages ​​to communicate and convey their thoughts, ideas, messages, and actions to others, in the same way, to communicate with computers, a computer understandable language is required, known as Programming Language.  Thus, a programming language is a way to communicate with the computer and provide instructions to the computer so that the computer can execute our tasks.  Computer Programming is the process of designing and building programs in order to execute the instructions successfully.  The demand for computer programming has increased highly, and people are learning computer programming as they find a good interest in such a field.  Programming is performed by Coding, and we create programs by writing codes on the computer.  Computer code is the logic of a human mind that we create for executing our instructions and get the results accordingly.  Using computer programming concepts, we can analyze, develop, and implement several algorithms that

User input in python?

  User input in Python 1. input()  is a predefined function which is used to take user input in Python. 2.Default user input is of type string. Userinput of String Value name = input ( "Enter your name:" ) print ( "Your name:" ,name) #Printing of data type of name print ( type (name)) """ ***Output*** Enter your name:Aayushi Your name: Aayushi <class 'str'=""> """ < / class > Userinput of Integer Value 1. int()  is a predefined function which is used to convert string into integer. #method 1 number = input ( "Enter any number:" ) print ( "Type of number:" , type (number)) #converting string into integer num = int (number) print ( "Given Number:" ,num) #Printing of data type of num print ( "Type of number:" , type (num)) """ ***Output*** Enter any number:204 Type of number: <class 'str'=""> Given Number: 204 Type of number:

Variable in python?

  Variable in Python It is a name of storage space which is used to store data. It's value may be changed. It always contains last value stored to it. There is no need to declare a variable in python. Variable is created by assigning a value to it. Variable Initialization name = "Tom" rollno = 205 marks = 85.6 Here name rollno and marks are the name of variables. Value of name is Tom,rollno is 205 and marks is 85.6 Printing value of variable We can print the value of a variable using print() function. #creating variables name = "Tom" rollno = 205 marks = 85.6 #printing value of varibales print ( "Name:" ,name) print ( "Roll:" ,rollno) print ( "Marks:" ,marks) """ ***Output*** Name: Tom Roll: 205 Marks: 85.6 """ Assigning single value to multiple variable We can assign a single value to multiple variables using single statement in python. #creating variables a = b = c = 90 #printing value o

How to run python program?

Image
  Run Program in Python IDLE IDE (PyCharm) To run Python script on a  IDE (Integrated Development Environment) like PyCharm , you will have to do the following: Create a new project. Give a name to that project as ‘GfG’ and click on Create. Select the root directory with the project name we specified in the last step.  Right click  on it, go in  New  and click on ‘ Python file ’ option. Then give the name of the file as ‘ hello ’ (you can specify any name as per your project requirement). This will create a ‘ hello.py ’ file in the project root directory. Note:  You don’t have to specify the extension as it will take it automatically. Now write the below Python script to print the message: print ( 'Hello World !' ) To run this python script,  Right click  and select ‘ Run File in Python Console ’ option. This will open a console box at the bottom and show the out put there. We can also run using the  Green Play Button  at the top right corner of the IDE. Output: