Draw the actual expression that the user inputted

Assignment Help Python Programming
Reference no: EM133013879

CPSC 231: Introduction to Computer Science

Assignment: Graphing Calculator

Collaboration

Discussing the assignment requirements with others is a reasonable thing to do, and an excellent way to learn. However, the work you hand-in must ultimately be your work. This is essential for you to benefit from the learning experience, and for the instructors and TAs to grade you fairly. Handing in work that is not your original work, but is represented as such, is plagiarism and academic misconduct. Penalties for academic misconduct are outlined in the university calendar.

Here are some tips to avoid plagiarism in your programming assignments.
1. Cite all sources of code that you hand-in that are not your original work. You can put the citation into comments in your program. For example, if you find and use code found on a web site, include a comment that says, for example:
# the following code .
Use the complete URL so that the marker can check the source.
2. Citing sources avoids accusations of plagiarism and penalties for academic misconduct. However, you may still get a low grade if you submit code that is not primarily developed by yourself. Cited material should never be used to complete core assignment specifications. You can and should verify and code you are concerned with your instructor/TA before submit.
3. Discuss and share ideas with other programmers as much as you like, but make sure that when you write your code that it is your own. A good rule of thumb is to wait 20 minutes after talking with somebody before writing your code. If you exchange code with another student, write code while discussing it with a fellow student, or copy code from another person's screen, then this code is not yours.
4. Collaborative coding is strictly prohibited. Your assignment submission must be strictly your code. Discussing anything beyond assignment requirements and ideas is a strictly forbidden form of collaboration. This includes sharing code, discussing code itself, or modelling code after another student's algorithm. You can not use (even with citation) another student's code.
5. Making your code available, even passively, for others to copy, or potentially copy, is also plagiarism.
6. We will be looking for plagiarism in all code submissions, possibly using automated software designed for the task.

Part 1: get_color:
First, complete the colour-determination function get_color. This function takes the counter tracked in the expression input loop and returns one of three different colours: red, green, or blue. You should find the remainder division operator (also called modulus) helpful here because it allows you to change an infinitely increasing integer sequence into a range of integers.

There are 3 sub-functions to this part. Each does not take a lot of code, but needs to be mathematically sound.
First, complete the coordinate conversion function calc_to_screen_coord. This function uses the parameters that the main function obtains user defined pixel coordinate system (x_origin, y_origin, ratio), along with a calculator coordinate system (????, ????) to perform the conversion. The (x_origin, y_origin) is the pixel coordinates of where (0, 0) in the calculator should be located on screen, and ratio is how many pixels are equal to 1 in the calculator coordinate system. calc_to_screen_coord returns the (x, y) coordinate as a pixel screen coordinate (screen_x, screen_y) following the math described previously in the example. Use this function in your code any time you want to convert and draw a calculator location. You will lose marks if you duplicate the math/code functionality of this function somewhere else instead of using this function designed for that purpose.

Part 4: draw_expression

Finally, you will draw the actual expression that the user inputted. Python can evaluate a string using its eval function. Your code does not need to be capable of anything more than the eval function can do. For example, the following 3-line program is a simple calculator that works for input like "1+1":
expression = input("Enter an arithmetic expression: ") result = eval(expression)
print("The result of that expression is", result)

Python is also able to evaluate expressions which include a single variable x. The implementation of this function can be surprising at first. When the eval function is called, it uses whatever value is stored in the variable called x to evaluate the given expression.
To make things easier a calc function has already been completed that will take an expression and an x and return the y value. (Ex. y = calc(expression, x)). You will use the eval() method to do all of your math for you for the calculator. You will notice that we have the import at the top from math import * which allows eval() to use things like cos/sin.
As a result, your program will need to include a variable named x, which represents the x coordinate in the calculator coordinate system. The value of x will change in a loop. Call calc inside of the loop so that you can compute the value of y for many different x values. For example, the following program evaluates an expression that includes the variable x for each integer value of x from 0 up to and including 5:
expr = input("Enter an arithmetic expression: ") for x in range(0, 6):
y = calc(expr, x)
print("When x is", x, "the value of the expression is", y)

You can use a similar technique to compute the y position of the curve for many different values of x. Those x and y values are what you need to draw short lines with turtle that will visually emulate the expression's lines and possible curvature.

You cannot complete this function correctly unless the previous functions are operational. In particular, it will be useful to use calc_minmax_x to determine which values of x you want to draw a line between. You will need to pick a delta that makes the curve smooth. A delta of 0.1 or 0.2 should provide sufficient smoothness. Note that, once you are using floating point values for your steps size, you will be unable to use a for-range() loop to loop through them but instead should use a while loop.

Attachment:- Graphing Calculator.rar

Reference no: EM133013879

Questions Cloud

Discuss the disadvantages of chosen strategies : Besides downsizing, discuss three other strategies local retailers could implement to address labour surplus in light of a temporary decline of sales at their m
What became the affordable care act : What was the basis or model for what became the Affordable Care Act?
Determine the value of ending inventory : Determine the value of ending inventory and materials used under the following methods: Sept. 1 Beginning balance 300 P12 P3,600
Write an essay on business strategies and hrm : Write an essay on business strategies and HRM
Draw the actual expression that the user inputted : Draw the actual expression that the user inputted. Python can evaluate a string using its eval function. Your code does not need to be capable of anything more
How many tubs should EBP produce : The glass and ceramic sinks and tubs require the use of specialized molding equipment. How many tubs should EBP produce
Split between the eastern and western churcches : What caused the split between the Eastern and Western Churcches?
Common employment visas for non-immigrant workers : The global economy necessitates the need for work visas in the United States. What are the most common employment visas for non-immigrant workers?
Calculate the estimated total cash receipts : ABC Ltd is a retailer of ladies' fashion and has the following historical collection pattern for its credit sales: Calculate the estimated total cash receipts

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