How to create a function like f(y) = xy^2 in Python?

0 votes
I want to write a function for f(y) = xy^2 in Python. Like if I pass value such as f(3) then it should give output as 9x. How to do it?
Aug 5 in Python by Arvind
• 2,960 points

1 answer to this question.

0 votes

This is very easy. have a look at the following code - 

>>> def f(y):
       return str(y**2) + 'x'
>>> f(9)


And if you have the value of constant then 

def f(y):
  return x*(y**2)
>>> f(2)

Suppose you have a polynomial equation such as 

p(x)=x4−4⋅x2+3⋅xp(x)=x4−4⋅x2+3⋅x then in this case :

>>> def p(x):
    return x**4 - 4*x**2 + 3*x
>>> p(2)

answered Aug 5 by Neel
• 3,010 points

edited Aug 6 by Kalgi

Related Questions In Python

+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 68,480 points

edited Aug 8, 2018 by Omkar 1,379 views
0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29 in Python by Nymeria
• 3,520 points
0 votes
1 answer

How to create a GUID/UUID in Python

The uuid module, in Python 2.5 and ...READ MORE

answered Jan 29 in Python by SDeb
• 13,210 points
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 416 views
+4 votes
6 answers
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is and ...READ MORE

answered Jun 26 in Python by Neel
• 3,010 points
0 votes
1 answer

How to check if a given string matches a particular pattern in Python?

You can use re module of python ...READ MORE

answered Jul 3 in Python by Neel
• 3,010 points