# Python Homework Help, Project Help, Python Assignment Solution

This is the only site to come to for help with your Python problems. If you are looking for help with Python then, I can’t think of anywhere else where you can get better service.

Our experts who offer Python programming homework help to the students, explain Python as an interpreted, interactive, object-oriented, and a high-level programming language.

Python is one of the object-oriented scripting language and is designed in a way which is highly readable. Students learning this language find it interesting as this language uses English keywords and is easy to understand. Though students find their python homework assignments too difficult to solve, they look for python programming homework to solve their questions from our team of experts.

For a change I’ll start with the output rather than the code. This is a calculator that uses RPN (reverse polish notation), this is where the operator follows the numbers, so instead of 2 + 2, you have 2 2 +.

```RPN expression:?
RPN Calculator (Simple Forth)
Enter expressions in reverse polish notation with spaces between each token
For example 2+3 in reverse polish is 2 3 +, you have the basic mathematic
operations available, +,-,*,/ in addition to % (modulo) ** (power)
You also have the sin,cos,tan and log. You can store a value in a variable
with var name, and retrieve the value with just using name. e and pi are already
defined for you. There are 2 user defined functions that are also already defined
fahrenheit which converts degrees centigrade to fahrenheit and the reverse.
You can define you own words, with def, so to make a shorter version of
fahrenheit, you can just use def f fahrenheit : . You can see all the words
already defined with words. ? will bring up this help, int will convert a value
to it's integer, exit or quit will end the program. You shouldn't need them, but
dup duplicates the top stack entry, and swap, swaps the top 2 entries around.
You can enter numbers in hexadecimal by prefixing then with \$, and binary numbers
by prefixing them with %. You can show a number in binary with bin, or in

RPN expression:3 4 -
-1.0
RPN expression:3 4 swap -
1.0
RPN expression:3 4 /
0.75
RPN expression:3 4 5 6 7 + * - /
-0.0491803278689
RPN expression:100 var boiling
RPN expression:boiling fahrenheit
212.0
RPN expression:def & and hex :
RPN expression:3 5 &
\$1
RPN expression:255 43 &
\$2b
RPN expression:255 bin
%11111111
RPN expression:words
fahrenheit : ['9', '*', '5', '/', '32', '+']
celsius : ['32', '-', '5', '*', '9', '/']
& : ['and', 'hex']
RPN expression:def deg 180 * pi / :
RPN expression:45 deg sin
0.806075491116
RPN expression:def deg pi * 180 / :
RPN expression:45 deg
0.785398163397
RPN expression:45 deg sin
0.707106781187
RPN expression:90 sin
0.893996663601
RPN expression:90 deg sin
1.0```

3 4 – = -1 and 3 4 swap – = 1 because it swaps the top 2 values, so it is the same as 4 3 -.

100 var boiling means push 100 to the stack, then define a variable, named boiling. It is then
used in boiling fahrenheit (we could have written this as 100 fahrenheit). def & and hex : is used to
define a function, the def starts a function definition (& is used here), it uses and to and 2 values
together, and then hex to display the value and the : ends the definition. words lists the definitions
of the commands, including the 2 built in ones as well as any user defined ones. Trigonometry functions
use radians, so if want to use degrees a small function such as def deg 180 * pi / : allows you to do
45 deg sin to get the sin of 45 degrees. Ok, now lets get on with the code.

Therefore, the learners who do not have a clear concept of object orientation seek Python live help from us. It is a new technology having advanced features, for which students take help with Python homework assignments to know more about the subject.

Students often take help from our tutors for their complex queries and usually just ask please do my python homework and our experts provide accurate solutions to them. Python is processed at runtime by the interpreter and is similar to PERL and PHP. Our service has been recognized as one of the best for Python assignment solutions.

## rpn.py

```import re,math

number = re.compile(r"-?[0-9]*\.?[0-9]+\$|-?[0-9]+\.?[0-9]*\$|\d+\.?\d*e[+-]?\d+",re.IGNORECASE)
hexnumber = re.compile(r"\\$[0-9a-f]+\$",re.IGNORECASE)
binarynumber = re.compile(r"%[01]+\$")

words = {'celsius' : "32 - 5 * 9 /".split(), 'fahrenheit' : "9 * 5 / 32 +".split()}
vars = {'e' : math.e, 'pi' : math.pi}
stack = []

running = True

def pop():
if len(stack):
return stack.pop()
else:
print "ERROR: stack empty"
return 0

def push(var):
stack.append(var)

def quit(tokens):
global running
running = False

left = pop()
right = pop()
push(left+right)

def subtract(tokens):
right = pop()
left = pop()
push(left-right)

def multiply(tokens):
left = pop()
right = pop()
push(left*right)

def divide(tokens):
right = pop()
left = pop()
if right:
push(left/right)
else:
print "ERROR: Division by zero"

def bit_and(tokens):
right = pop()
left = pop()
push(int(left) & int(right))

def bit_or(tokens):
right = pop()
left = pop()
push(int(left) | int(right))

def bit_xor(tokens):
right = pop()
left = pop()
push(int(left) ^ int(right))

def bit_not(tokens):
num = pop()
push(~int(num))

def modulo(tokens):
right = pop()
left = pop()
if right:
push(left/right)
else:
print "ERROR: Modulo by zero"

def power(tokens):
right = pop()
left = pop()
push(left**right)

def show(tokens):
left = pop()
print left
push(left)

def duplicate(tokens):
left = pop()
push(left)
push(left)

def pop_off(tokens):
left = pop()

def list(tokens):
print stack

def display_words(tokens):
for word in words:
print word,':',words[word]

def define(tokens):
colon = tokens.index(':')
if colon <= 0:
print "ERROR: Invalid word defintion"
return
else:
words[tokens[0]] = tokens[1:colon]
return colon+1

def variable(tokens):
vars[tokens[0]] = pop()
return 1

def integer(tokens):
left = pop()
push(int(left))

def sin(tokens):
left = pop()
push(math.sin(left))

def cos(tokens):
left = pop()
push(math.cos(left))

def tan(tokens):
left = pop()
push(math.tan(left))

def log(tokens):
left = pop()
push(math.log(left))

def pop_off(tokens):
pop()

def swap(tokens):
left = pop()
right = pop()
push(left)
push(right)

left = pop()
hexval = hex(int(left))[2:]
if hexval[-1] == 'L':
hexval = hexval[:-1]
print '\$' + hexval

def binary(tokens):
left = pop()
print '%' + bin(int(left))[2:]

def help(tokens):
print """RPN Calculator (Simple Forth)
Students who have doubts in Python can avail our online Python help chat.
Students seek assignment code in Python to solve their complex or simple
assignment problems by contacting us with their python assignment questions.
Beginners also seek our help saying ‘do my Python homework’ on live chat or
email and then our experts guide them to solve their problem.

Enter expressions in reverse polish notation with spaces between each token
For example 2+3 in reverse polish is 2 3 +, you have the basic mathematic
operations available, +,-,*,/ in addition to % (modulo) ** (power)
You also have the sin,cos,tan and log. You can store a value in a variable
with var name, and retrieve the value with just using name. e and pi are already
defined for you. There are 2 user defined functions that are also already defined
fahrenheit which converts degrees centigrade to fahrenheit and the reverse.
You can define you own words, with def, so to make a shorter version of
fahrenheit, you can just use def f fahrenheit : . You can see all the words
already defined with words. ? will bring up this help, int will convert a value
to it's integer, exit or quit will end the program. You shouldn't need them, but
dup duplicates the top stack entry, and swap, swaps the top 2 entries around.
You can enter numbers in hexadecimal by prefixing then with \$, and binary numbers
by prefixing them with %. You can show a number in binary with bin, or in
"""

cmds = {'+' : add, '-' : subtract, '*' : multiply, '/' : divide, '%' : modulo, 'int' : integer, '**' : power,
'and': bit_and, 'or' : bit_or, 'xor' : bit_xor, 'not' : bit_not,
'sin' : sin, 'cos' : cos, 'tan' : tan, 'log' : log, 'hex' : hexadecimal, 'bin' : binary,
'.' : show, 'dup' : duplicate, 'pop' : pop_off, 'list' : list, 'words' : display_words, 'def' : define,
'var' : variable, '?' : help, 'exit' : quit, 'quit' : quit, 'swap' : swap}

def calc(expr):
tokens = expr.lower().split()
i = 0
while i < len(tokens):
token = tokens[i]
i += 1
if number.match(token):
push(float(token))
elif hexnumber.match(token):
push(int(token[1:],16))
elif binarynumber.match(token):
push(int(token[1:],2))
else:
if token in cmds:
if i < len(tokens):
tail = tokens[i:]
else:
tail = []
skip = cmds[token](tokens[i:])
if skip:
i += skip
elif token in vars:
push(vars[token])
elif token in words:
pos = i
for word in words[token]:
tokens.insert(pos,word)
pos += 1
else:
print "ERROR. Invalid token:",token

if stack:
return pop()

while (running):
expr = raw_input("RPN expression:")
expr = calc(expr)
if expr != None:
print expr```

### Global variables

```number = re.compile(r"-?[0-9]*\.?[0-9]+\$|-?[0-9]+\.?[0-9]*\$|\d+\.?\d*e[+-]?\d+",re.IGNORECASE)
hexnumber = re.compile(r"\\$[0-9a-f]+\$",re.IGNORECASE)
binarynumber = re.compile(r"%[01]+\$")

words = {'celsius' : "32 - 5 * 9 /".split(), 'fahrenheit' : "9 * 5 / 32 +".split()}
vars = {'e' : math.e, 'pi' : math.pi}
stack = []```

number is a regular expression that allows 123, 123.45, 123.45e67 (so integer or floating point).

hexnumber is a hexadecimal value and binarynumber is for a binary value.

words is a dictionary with a couple of defined functions.

vars are constant numbers.

stack is where the temporary results are stored.

Our online experts offer Python live help to those students who look for help from the scratch. Students have also found our Python programming homework to be very useful as they can study the code explained with comments by our tutors. Our well skilled experts offer Python homework assignments, as they know most of the learners struggle to prepare their assignments on time with accuracy.

### Push and Pop

```def pop():
if len(stack):
return stack.pop()
else:
print "ERROR: stack empty"
return 0

def push(var):
stack.append(var)```

pop is used to get a result off the stack, and push, is used to push a number or a result.

### Basic Mathematical Functions

```def add(tokens):
left = pop()
right = pop()
push(left+right)

def subtract(tokens):
right = pop()
left = pop()
push(left-right)

def multiply(tokens):
left = pop()
right = pop()
push(left*right)

def divide(tokens):
right = pop()
left = pop()
if right:
push(left/right)
else:
print "ERROR: Division by zero"

def bit_and(tokens):
right = pop()
left = pop()
push(int(left) & int(right))

def bit_or(tokens):
right = pop()
left = pop()
push(int(left) | int(right))

def bit_xor(tokens):
right = pop()
left = pop()
push(int(left) ^ int(right))

def bit_not(tokens):
num = pop()
push(~int(num))

def modulo(tokens):
right = pop()
left = pop()
if right:
push(left/right)
else:
print "ERROR: Modulo by zero"

def power(tokens):
right = pop()
left = pop()
push(left**right)```

As Python is designed as a highly readable scripting language, which uses English keywords frequently, it is easier for students to understand the language and hence usually beginners go for Python programming assignments.

These functions pop 1 or 2 values off the stack and manipulate them and push the result back onto the stack.

### def show

```def show(tokens):
left = pop()
print left
push(left)```

Show the value at the top of the stack (does not pop the value).

### def duplicate

```def duplicate(tokens):
left = pop()
push(left)
push(left)```

Make a copy of the top value on the stack, so if you want to square a number, you could dup then *.

### def pop_off

```def pop_off(tokens):
left = pop()```

Remove the top value from the stack.

### def list

```def list(tokens):
print stack```

Show the contents of the stack.

### def display_words

```def display_words(tokens):
for word in words:
print word,':',words[word]```

List all the defined functions.

### def define

```def define(tokens):
colon = tokens.index(':')
if colon <= 0:
print "ERROR: Invalid word defintion"
return
else:
words[tokens[0]] = tokens[1:colon]
return colon+1```

Define a function, the first token is the function name, and ends when a colon is encountered.

### def variable

```def variable(tokens):
vars[tokens[0]] = pop()
return 1```

The first token gives the name of the variable.

Students who have queries can take the benefit from our online Python help chat. Our experts who offer help with python assignments to the students, also provide well solved python programming solutions. Our Python online tutors offer Python programming project help to the learners who are seeking help to solve their assignment projects. We provide highly efficient and skilled experts who offer their services in Python programming homework help 24 / 7.

Students often take help from our tutors for their complex queries and usually just ask please do my python homework and our experts provide accurate solutions to them. Python is processed at runtime by the interpreter and is similar to PERL and PHP. Our service has been recognized as one of the best for Python assignment solutions.

### def integer

```def integer(tokens):
left = pop()
push(int(left))```

Convert the top value into an integer.

### Trigonometry functions

```def sin(tokens):
left = pop()
push(math.sin(left))

def cos(tokens):
left = pop()
push(math.cos(left))

def tan(tokens):
left = pop()
push(math.tan(left))

def log(tokens):
left = pop()
push(math.log(left))```

More math functions.

### def swap

```def swap(tokens):
left = pop()
right = pop()
push(left)
push(right)```

Swap the top 2 values on the stack.

```def hexadecimal(tokens):
left = pop()
hexval = hex(int(left))[2:]
if hexval[-1] == 'L':
hexval = hexval[:-1]
print '\$' + hexval```

Display the top value as a hexadecimal number.

### def binary

```def binary(tokens):
left = pop()
print '%' + bin(int(left))[2:]```

Display the top value as a binary number.

### Command dictionary

```cmds = {'+' : add, '-' : subtract, '*' : multiply, '/' : divide, '%' : modulo, 'int' : integer, '**' : power,
'and': bit_and, 'or' : bit_or, 'xor' : bit_xor, 'not' : bit_not,
'sin' : sin, 'cos' : cos, 'tan' : tan, 'log' : log, 'hex' : hexadecimal, 'bin' : binary,
'.' : show, 'dup' : duplicate, 'pop' : pop_off, 'list' : list, 'words' : display_words, 'def' : define,
'var' : variable, '?' : help, 'exit' : quit, 'quit' : quit, 'swap' : swap}```

The command functions for each token.

Our experts who offer python homework solution provides several coding samples for the beginners who scuffle for it; they get help with Python homework. Students find help with Python assignment know about this technology that help in their studies.

### def calc

```def calc(expr):
tokens = expr.lower().split()
i = 0
while i < len(tokens):
token = tokens[i]
i += 1
if number.match(token):
push(float(token))
elif hexnumber.match(token):
push(int(token[1:],16))
elif binarynumber.match(token):
push(int(token[1:],2))
else:
if token in cmds:
if i < len(tokens):
tail = tokens[i:]
else:
tail = []
skip = cmds[token](tokens[i:])
if skip:
i += skip
elif token in vars:
push(vars[token])
elif token in words:
pos = i
for word in words[token]:
tokens.insert(pos,word)
pos += 1
else:
print "ERROR. Invalid token:",token

if stack:
return pop()```

First of it breaks the line into a series of tokens, it loops through each token. It checks if it is a numeric
value, if it is then it pushes the value, then it checks if the token is a built in command, or a variable, and
then finally a user defined function. If it is a command, it calls the function with the remaining tokens on the
line and uses the return value to skip the next n tokens. If the token is a user defined function, then copy the
tokens that make the function up into the current token stream.

## Suggested inprovements

You could make it so that if it is used from the command line it exits after performing the calculation, and saves
the state and restores it on each use. That would make a handy calculator replacement.

A more ambitious expansion would be to allow conditional functions and loops, and you could have a useful mini language.

Our experts, offer python programming assignments for beginners and discuss about Python as a great language for the beginner-level programmers that supports the development of a wide range of applications. Students get assignment questions related to functional and structured programming methods as well as OOP so they take our help with Python homework from our expert tutors. Experts have observed that several python assignment questions are related to the various topics like automatic garbage collection, dynamic data types, dynamic type checking, etc. This language is also integrated with C, ActiveX, C++, COM, CORBA, and Java. Students avail the benefits of python homework problems where they can interact with our experts and get the required solution. Even our tutors provide python live help for the learners who are also trying to solve their project related questions. Students can anytime avail our online python help chat with the experts who are highly experienced and skilled in their relevant subjects. We are one of the best python assignment solution provider and our experts are dedicated to give their best to gain student satisfaction more and more.

We provide excellent online services as our experts are capable for solving many complex assignment solutions, considered as one of the best who offer Python programming assignment help.