2. The shape of a lima¸con can be defined parametrically as
r = r0 + cos θ
x = r cos θ
y = r sin θ
When r0 = 1, this curve is called a cardioid. Use this definition to plot the shape of a limacon for r0 = 0.8, r0 = 1.0, and r0 = 1.2. Be sure to use enough points that the curve is closed and appears smooth (except for the cusp in the cardioid). Use a legend to identify which curve is which.
1. Use matplotlib.pyplot.plot to produce a plot of the functions f(x) = e−x/10 sin(πx) and g(x) = xe−x/3 over the interval [0, 10]. Include labels for the x- and y-axes, and a legend explaining which line is which plot.
Define the following vectors and matrices:
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]]
13. The function np.random.rand can be used to construct and fill vectors and matrices with random numbers. Use the help facility in Python to learn how to construct a 10 × 10 matrix named M filled with random numbers.
Define the following vectors and matrices:
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]]
10. What function would you use to find the value of j so that vec1[j] is equal to the smallest element in vec1?
11. What expression would you use to find the smallest element of the matrix
mat1?
Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B.
Input
The first line contains a single integer M.
Next M lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes co-efficient of Pi for polynomial A.
After that next line contains a single integer N.
Next N lines contain two integers Pj, Cj separated with space, where Pj denotes power and Cj denotes co-efficient of Pj for polynomial B.
Output
Explanation
If M = 4 and for polynomial A
For power 0, co-efficient is 5
For power 1, co-efficient is 0
For power 2, co-efficient is 10
For power 3, co-efficient is 6.
If N = 3 and for polynomial B
For power 0, co-efficient is 1
For power 1, co-efficient is 2
For power 2, co-efficient is 4.
sample output :
"6x^3 + 14x^2 + 2x + 6"
sample Input:
4
0 5
1 0
2 10
3 6
4
0 -5
1 0
2 -10
3 -6
sample output:
input:
1 20 3
30 10 2
5 11 15
output:
[[1, 2, 3], [5, 10, 11], [15, 20, 30]]expected output:
1 2 3
5 10 11
15 20 30 Temperature Conversion
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places
Explanation
For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.
When input is "python learning" output displayed is 16-25-20-8-15-14- 12-5-1-18-14-9-14-7 there is additional - after 14 digit. how to rectify this ,kindly guide me?
while run this code
input: python
and it show out is :
kbgslm
Errors/Warnings:
Traceback (most recent call last):
File "main.py", line 8, in <module>
inp = input()
EOFError: EOF when reading a line
expected output:
kbgslm
One Color
Given a string of length N, made up of only uppercase characters 'R' and 'G', where 'R' stands for Red and 'G' stands for Green. Find out the minimum number of characters you need to change to make the whole string of the same colour.
Input
The input will be a single line containing a string.
Output
The output should be single line containing the integer representing the minimum number of characters you need to change to make the whole string of the same colour.
Explanation
For example, if string is "GGGGGGR" . We need to change only the last character to 'G' to make the string same-coloured.
then output is 1.