Programmer does not have to use the def statement

Assignment Help Python Programming
Reference no: EM13164477

Consider a very simple programming language named Z+-. The Z+- programming language has the following features:

  • Every program can declare integer variables, using case-sensitive alphabetic identifiers. This is done using the DEF statement:

               DEF hello ;

    All declared variables are automatically initialized to 0.
  • At the end of the program, all the variables are printed to the console in alphabetical order (this is the only form of output). Again, there are no explicit statements to do this printing; it is done implicitly.
  • The right-hand side of a simple assignment statement (i.e., =) is either a variable name or unsigned integer. For example, the following are valid:

A = 12 ;

A = B ;

  • There are two assignment statements: +=, *=, and -=. These have their usual meaning:

A += 34 ;

A *= B ;

  • Every statement is terminated by a semi-colon.
  • There is a loop statement - FOR - whose body contains at least one simple statement (i.e., no nested loops), which are on presented on one line. The keyword FOR is followed by a number, which indicates the number of times to execute the loop. Following this number is a sequence of statements defining the loop's body, followed by the word ENDFOR.
  • Z+- programs must have at least one space separating all lexical elements.


Here is an example Z+- program:

DEF A ;
DEF B ;
A = 1 ;

FOR 5 B += A ; A *= 2 ; ENDFOR

A += 1000 ;

This program's output is:

A=1032

B=31

An equivalent Java program would be:

public static void main(String [] args)

{

int A=0;
     int B=0;

A = 1;

for (int i=0; i<5; i++) {

B += A;

A *= 2;

}

A += 1000;

     System.out.println("A=" + A);

System.out.println("B=" + B);

}

Z+- did not acquire any faithful users; therefore, the designer developed Z+-+. Z+-+ has the following features:

  • Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.
  • Z+-+ for loops can be nested:

FOR 5 B += A ; A *= 2 ; FOR 10 A += B ; ENDFOR ENDFOR

  • You may assume that the programs are syntactically correct and will not cause arithmetic errors.

Reference no: EM13164477

Questions Cloud

State what is the reaction order with respect to no : Plot NO2 versus time, ln NO2 vs time, and 1/NO2 vs time. Which graph yields the best straight line? what is the reaction order with respect to NO2? Briefly explain
How many molecules of ethanol are present : How many molecules of ethanol are present in 125mL of ethanol? The density of ethanol is 0.789g/cm^3.
State the normal boiling point of ethanol : The normal boiling point of ethanol (C2H5OH) is 78.3 °C and its molar enthalpy of vaporization is 38.56 kJ/mol. What is the change in entropy in the system in J/K when 62.2 grams of ethanol
Design, write, and test a program : Design, write, and test a program that represents some of the aspects of a student
Programmer does not have to use the def statement : Unlike Z+-, the programmer does not have to use the DEF statement to create a variable. Instead, the programmer can simply use the variable. The first use of the variable creates it and initializes it to 0.
State the complete eigen-function of the molecule : Before the collision what is the complete Eigen-function of the molecule? assuming the surface is located at x=0, and V (x =0)=0 and tha tthe molecule is located at a position X>>0. which means the molecule can be treated as a free mass in the re..
Implement a class to represent a matrix : Implement a class to represent a matrix. While doing this exercise, you are allowed only to use C++ primitive types and arrays. You may not use STL in your Matrix definition. You must use dynamic memory.
A lock variable not a good solution for mutual exclusion : why is busy waiting on a lock variable not a good solution for mutual exclusion?
Linear-time algorithm for computing the strong component : On the basis of a linear-time algorithm for computing the strong component containing a given vertex v, describe a simple quadratic-time algorithm for computing the strong components of a digraph.

Reviews

Write a Review

Python Programming Questions & Answers

  Define a function to calculate the values

Be sure to define a function to calculate the values and print the table displaying the interest rate in the first column, the monthly payment in the second column, and the total payment in the third column. Your program should not allow the user to ..

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write a program to receive a series of numbers

Write a program to receive a series of numbers (including decimal) from the user until enter key is pressed. Process the input data and display number count, sum and average. Use proper data type and format.

  Most popular name would be the one with the biggest number

the program will ask you to insert the year that the user is interested in, then ask the gender that the user is interested in, and print out the most popular names corresponding to the year and gender. FYI, the number on the right represents how man..

  Program to do the enciphering

Write a program to do the enciphering. It should prompt the user for a message, and print out both the entered message and its corresponding ciphertext.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Console program where you will implement

Create a console program where you will implement coding constructs and variables that are needed for this program and will implement the code within Main and any required static methods.

  Write a function trans(m) which returns the transpose

Write a function trans(M) which returns the transpose of an n-by-n matrix M. The matrix M is represented by a list of n lists, each of length n. Transposing M means that each M[i][j] is swapped (once!) with M[j][i].

  Function by sum of sines

code the program using an editor (DO NOT COMMAND LINE THE PROGRAM) and show the results

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Project will be a simple, working program

This programming project will be a simple, working program, using Python language, which utilizes a good design process and includes:Sequential, selection, and repetitive programming statements as well as,At least one function call.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd