0

Currently trying to set up this function and its giving me errors when defining minus as a variable. I know its the way I set it up, but I cant find anything on the correct setup. Can someone point me in the right direction?

def horizontal(k):
    plus = "+"
    minus = "-"*((k-3)/2)
    print(plus,minus,plus,minus,plus)

horizontal(5)

should be giving an output of +-+-+

1
  • Wow sorry about the formatting, will fix in a second Commented Jan 7, 2017 at 23:11

1 Answer 1

1

The problem is you are running python 3 (it would work fine in python 2.X), where division returns float, and you cannot multiply string by float, change your minus line to

minus = "-" * int((k-3)/2)

then it produces

+ - + - +
Sign up to request clarification or add additional context in comments.

1 Comment

Could also just change / to //. Single character alteration to fix the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.