Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

 

Every programming language has to have  some method for indicating grouping of operations. Here is how you execute an if-then-else structure in Java:

 

if (s == 1){

s = s + 1;

a = a - 10;

} else {

s = s + 10;

a = a + 10;

}

 

The braces  specify  what  statements are executed in the  if case.  It is suppose good  method  to indent your  code to agree  with  the brace structure, but it is not needed. In addition, the semi colons are used  to show the end of a instruction, independent of the position of the line divided in the file. So, the following code segment has the same meaning as the previous one, although it is much typical to read  and understand.

 

if (s == 1){

s = s

+ 1;      a = a - 10;

} else {

 a = a + 10;

}

 

In Python, on the  other  hand, there  are no braces  for grouping or semicolons for ending. Indentation shows grouping and line breaks  indicate statement ending. So, in Python, we would give the previous example as

 

if s == 1:

s = s + 1

a = a - 10

else:

s = s + 10

a = a + 10

 

There is no way to put  more  than  one statement on a one line.3  If you have  a instruction that  is too long for a line, you can break it with a backslash:

 

aReallyLongVariableNameThatMakesMyLinesLong = \

aReallyLongVariableNameThatMakesMyLinesLong + 1

 

It is easy for Java programmers to get confused about  colons and semi colons in Python. Here is the method:  (1) Python does  not use semi-colons; (2) Colons  are used  to start  an indented part, so they  seems on the ?rst  line of a method definition, when  starting  for loop or while loop,  and after the situation in an if, elif, or else.

Is one method better  than  the other?  No.  It is purely a function of taste.  The Python function is pretty unusual. But if you are using Python, you have to remember that indentation and line breaks are significant.

 

Python, Programming

  • Category:- Python
  • Reference No.:- M9505993

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Question a software company sells a package that retails

Question : A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program usi ...

Question write a simple python program that takes use

Question: Write a simple python program that takes use inputs as non-zero digits and converts them into binary form. The response must be typed, single spaced, must be in times new roman font (size 12) and must follow th ...

Question write a python program with a graphical user

Question: Write a python program with a graphical user interface that will allow a user to create a custom pizza which they wish to order. At minimum, the user should be able to choose the size of the pizza, the type of ...

Environment setupthe first mini project will be based on

Environment Setup The first mini project will be based on Ladder Logic programming. We will be using Schneider Electric's IDE called SoMachine Basic to do the programming. The latest ver- sion of SoMachine Basic for Wind ...

Simple python traffic lightswrite a program that simulates

Simple Python (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and onl ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As