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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  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 python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  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.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  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.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  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.

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