Python Forum
Can someone help me please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone help me please
#1
Hi i was wondering if someone could explain and help me Develop a Python function which either returns the float square of its parameter x if the parameter is a number, or prints the string "Sorry Dave, I'm afraid I can't do that" if the parameter is a string, and then returns 0.0.

It my lab project and im kind of confused on what its asking me to do
Reply
#2
What have you tried? We have an aversion to doing people's homework around her, but we are happy to help you fix problems with code you have written.

You'll need a def statement to define the function, the ** operator for getting the square, and probably a try/except block to handle the conditional output.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Oct-18-2017, 09:10 PM)ichabod801 Wrote: What have you tried? We have an aversion to doing people's homework around her, but we are happy to help you fix problems with code you have written.

You'll need a def statement to define the function, the ** operator for getting the square, and probably a try/except block to handle the conditional output.

hi thanks for the reply! ok so you said i need to define a function first what should i cal the function in this case? and could you break the task down for me in simpler words and like explain what its asking me to do please
thank you for the reply
Reply
#4
Call it whatever you want to call it.  It squares numbers sometimes, so why not name it what it does: square.

You should start by mocking up what you want to make, with some test data, so you can make sure the output is what you expect for a few different inputs.  Something like
# define your function here

tests = [4, 2.6, "spam", -3, 0]
for test in test:
    # call your function here
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020