user17361242
user17361242

Reputation:

how would i put this in the main()?

I have a coding assignment that needs the following:

Add a main() function to remove all code from global space

Add at least 1 function that gets called from the main function.

At least 1 function must take and use parameters

At least 1 function must return a value that your program uses

and this is what I have so far

color = str(input("What color turtle was drawing the shapes? ")).lower()
numofshapes = int(input("how many shapes did it draw? ")).lower()

def whatturtle(color,numofshapes):
    if color != "orange":
        answer1 = "you are colorblind"
    elif color != "blue":
        answer1 = "his name is leonardo"
    elif numofshapes != 5:
        answer2 = "he did not draw that amount of shapes"
    elif numofshapes = 5:
        answer2 = "he drew some regular polygons with 3,4,6,9,12 sides!"
return answer1
return answer2

#####
def main():

main()

what i am trying to do here is have the user say what was the color of the turtle that was drawing the shapes and how many shapes did it draw (which is blue and 5) i need that function inside the def main(), how would i do that? also the output i am trying to get is the program say "answer1 and answer 2" ( for example, "you are colorblind and he did not draw that amount of shapes" ) please help thank you!

Upvotes: 0

Views: 47

Answers (1)

ImSo3K
ImSo3K

Reputation: 872

def whatturtle(color, numofshapes):
    answer1, answer2 = '', ''
    if color != "orange":
        answer1 = "you are colorblind"
    elif color != "blue":
        answer1 = "his name is leonardo"
    if numofshapes != '5':
        answer2 = "he did not draw that amount of shapes"
    elif numofshapes == '5':
        answer2 = "he drew some regular polygons with 3,4,6,9,12 sides!"

    return answer1 + answer2


#####
def main():
  color = input("What color turtle was drawing the shapes? ").lower()
  numofshapes = input("how many shapes did it draw? ")
  print(whatturtle(color, numofshapes))


main()

input:

What color turtle was drawing the shapes? blue
how many shapes did it draw? 6

output:

you are colorblindhe did not draw that amount of shapes

You had some syntax errors, redundant code and un-reachable return statement;

  • If color did match, since everything was in elif statements it would never reach the conditions of answer2, so I added an if is more suitable in the 3rd condition.

  • The 4rd condition was numofshapes = 5 which is not really a condition but an assignment operator which returns a syntax error, an equality condition is written like this: ==.

  • The 2nd return return answer2 was unreachable since you returned answer already, in Python you can return more than 1 statement and I concatenated them with the + operator which is one of its functionalities for strings.

  • You tried to .lower() an int when inputting numofshapes, .lower() works on strings.

Upvotes: 3

Related Questions