Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

python - TypeError: create_purple() takes 0 positional arguments but 2 were given

I am brand new to Python programming and trying to make this program work.

I have made this program work by using "if" and "else" statements only, however, I wanted to make this same program with the method below. When I run the program I keep getting an error "TypeError: create_purple() takes 0 positional arguments but 2 were given" and I cannot figure out why.

Here is my code:

#*******************************************************************************************
#
# This program will take any two primary colors and create a secondary color.
#
# Primary colors are:
# Blue, Red, Yellow
# 
# Secondary colors are:
# Green, Orange, Purple
#

#Clear the screen
import os
os.system('cls') 

RED = "red"
BLUE = "blue"
YELLOW = "yellow"

def main():
    print ('
')
    # Tell the user the objective of the program.
    print ('*****************************************************************************')
    print ('*****************************************************************************')
    print ('
')
    print ('The objective of this program is to create a secondary color from two primary')
    print ('colors. When asked, choose two primary colors (Red, Blue, or Yellow) to create')
    print ('a secondary color ')

    # Choose your colors
    color1 = input('Enter your first primary color: ')
    color2 = input('Enter your second primary color: ')

    # Determine the secondary color
    if color1 == RED and color2 == BLUE:
    create_purple(color1,color2)


def create_purple():

    # Determine the color is purple
    if color1 == RED and color2 == BLUE:
        print ('
')
        print ('You have made the color.... Purple ')
    else:
        if color1 == BLUE and color2 == RED:
            print ('
')
            print ('You have made the color.... Purple ')

# Call the main function
main()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are calling create_purple with 2 arguments, yet your definition (def) has 0 arguments.

Simply update the definition:

def create_purple(color1,color2):

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...