Question

PYTHON:please display code in python

Part 1: Determining the Values for a Sine Function

Write a Python program that displays and describes the equation for plotting the sine function, then prompts the user for the values A, B, C and D to be used in the calculation. Your program should then compute and display the values for Amplitude, Range, Frequency, Phase and Offset.

Example input/output for part 1:

This program creates a vertical plot based on the function y A sin (B x C) D Where: Amplitude A Frequency B (2 pi) Phase -C B Offset D Please enter the values for: A 5 B 24 D 15 Amplitude 5 Range 10 Freqency: 3.82 Phase 0 Offset 15

Part 2: Displaying a Vertical Plot Header

A vertical plot of the output of a periodic function can be produced using a series of print statements. This will be a text-based representation of a graphical display. Before we display the results of our formula, it is important to create a ‘header’ showing the range of values represented and to make the plot easier to read and understand. Recall that the Range is the distance between the highest and lowest values, (or 2 * Amplitude), and the Offset represents the mid point of the values. The low, mid and high values for a periodic function are calculated as follows:

low = Offset – Amplitude

mid = Offset

high = Offset + Amplitude

Modify your Python program so that it displays the low, mid and high point values for our periodic function and a double-line border. (HINT: Print a series of “=” characters to create the border.) Your range values will determine the length of the border.

Example input/output for part 2:


Part 3: Display a Vertical, Text-Based Plot​

Using text to display vertical plot of a periodic function has its limits. One of these is the range of textbased plots must fit within the width of the display. Another is the loss of resolution due to the plot containing only spaces and characters, (ie: We cannot display 3.25 spaces). By converting our calculated values to integers, we can still achieve a close approximation to the correct values.

Modify your Python program so that it calculates the correct result (y) for all values (x) starting with 0 up to and including 45. Below the header you displayed in Part 2, print each value (x), then a series of spaces taking into account the lowest value in your range and the calculated result (y), then finally an asterisk character (*). NOTE: The sin() function expects values in radians.

For example, if the low value in your range (calculated in Part 2) was 1, the value for x=10 and the result of the formula was y=3, your program would display: “10     * “ (ie: 10 *)

Example input / Output for Part 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python code:

import math
import sys

print "Enter A"
A = float(raw_input().strip())
print "Enter B"
B = float(raw_input().strip())
print "Enter C"
C = float(raw_input().strip())
print "Enter D"
D = float(raw_input().strip())

Amplitude = A
Frequency = B/(2*math.pi)
Phase = -C/B
Offset = D
Range = 2*A

print "Amplitude: ", Amplitude
print "Frequency: ", Frequency
print "Range: ", Range
print "Offset: ", Offset
print "Phase: ", Phase
print " "*7,"Low"," "*7,"mid"," "*7,"high"
i = 0
x = 0
while(i<=45):
   space = A*(math.sin(B*x + C)) + D
   x = x + 0.01
   space = int(space)
   s = " "
   for y in range(0,space):
       s = s + " ";
   # print space
   sys.stdout.write(s)
   sys.stdout.write("*\n")
   i = i + 1
print "\n"

Sample Output:

akasndakash-SVE1S116ENBDesktop/HomeworkLib/stn pythons python code.Py Enter A 10 Enter B 15 Enter Enter D 20 Amplitude: 10.0 Freque

Add a comment
Know the answer?
Add Answer to:
PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am using python and I want to know how I can get the spacing between...

    I am using python and I want to know how I can get the spacing between the low mid and high to be dependent on the range and how I can get that boarder to be dependent on the range as well. Im not sure what you mean, I just want to know about the spacing. Modify your project1.py Python program so that it displays the low, mid and high point values for periodic function and a double-line border. (HINT:...

  • Part I: Code writing: 1. 3pts (Display matrix of numbers) Write a function that displays an...

    Part I: Code writing: 1. 3pts (Display matrix of numbers) Write a function that displays an n-by-n matrix using the following header: void printMatrix(int n) Each element is between (3,9), which is generated randomly. Write a test program that prompts the user to enter n and displays an n-by-n matrix. Here is a sample run: Enter n: 2 47 96

  • Only use the code in Objectives and write the code in Python

    Only use the code in Objectives and write the code in Python Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50 $60 $75 Are...

  • Write the code in Python. The output should be exact the same as the given.

    Write the code in Python. The output should be exact the same as the given. Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50...

  • PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """...

    PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the...

  • Lab 1 Q1. Write a Python program with the following function building block. •All input values...

    Lab 1 Q1. Write a Python program with the following function building block. •All input values are to be taken fro m the user. •Ensure to check for possible error cases like mismatch of data type and input out of range, for every function.       Function 1: countVowels(sentence) – Function that returns the count of vowels in a sentence. Function 2: Sum of all even numbers between two numbers, identify number of parameters   Q2. Write a Python program that reads a...

  • Python please Write a function print_back_upper() that accepts a string my_str as an argument and displays...

    Python please Write a function print_back_upper() that accepts a string my_str as an argument and displays the string backwards and in uppercase, all in one line (Note: Create any necessary variables) For example: if my_str = "Python" then, your output should display as follows: NOHTYP (Hint: You can use for loop navigating up to range of len of string-1, -1, -1 and use reverse() and upper() functions to create and display the string backwards in uppercase)

  • Write a program in python or c++ that has two functions: Function one is called: _encrypt...

    Write a program in python or c++ that has two functions: Function one is called: _encrypt Function Two is called: _decrypt Function one takes plain text ,and assesses the indexed value of each letter in the string. For example, a=1,b=2 . It then adds three to the indexed valus , and produces encrypted text , based off of the plain text. Function two reverse this. here is sample output: _encrypt(‘how do you do’) Unsecured: howdoyoudo Secured: lsahscsyhs _decrypt(‘lsahscsyhs’) Unsecured: lsahscsyhs...

  • Write a Python program with a function that will take as input from the user the...

    Write a Python program with a function that will take as input from the user the temperature in Celsius and will convert and display temperature values in both Fahrenheit and Celsius, using the equation: F = (C ∗ 9/5)+ 32 Note: below is what a sample input line to your program should look like and the resulting output. User input lines always start with >>>. This convention will be used for all of the problem sets. >>>Enter temperature in Celsius:...

  • Part 1 Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that...

    Part 1 Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a. while True: y = (x + a/x) / 2.0 if y == x: break x = y Part 2 Write a function named test_sqrt that prints a table like the following using a while loop, where "diff" is the absolute value of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT