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, 2019 in Python by Arvind
• 3,040 points
1,725 views

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)

'81x'

And if you have the value of constant then 

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

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)
6

answered Aug 5, 2019 by Neel
• 3,020 points

edited Aug 6, 2019 by Kalgi

Related Questions In Python

0 votes
1 answer

How to create lambda function inside a list in Python?

Hi@akhtar, The lambda statement can appear in places ...READ MORE

answered Jun 25, 2020 in Python by MD
• 95,440 points
455 views
+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 5, 2018 in Python by Omkar
• 69,210 points

edited Aug 8, 2018 by Omkar 7,609 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, 2019 in Python by Nymeria
• 3,560 points
1,754 views
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, 2019 in Python by SDeb
• 13,300 points
1,525 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,420 views
0 votes
1 answer

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

Suppose your file name is demo.py and ...READ MORE

answered Jun 26, 2019 in Python by Neel
• 3,020 points
728 views
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, 2019 in Python by Neel
• 3,020 points
959 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP