TypeError: create_purple() 接受 0 个位置参数,但给出了 2 个

TypeError: create_purple() takes 0 positional arguments but 2 were given(TypeError: create_purple() 接受 0 个位置参数,但给出了 2 个)
本文介绍了TypeError: create_purple() 接受 0 个位置参数,但给出了 2 个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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

Simply update the definition:

def create_purple(color1,color2):

这篇关于TypeError: create_purple() 接受 0 个位置参数,但给出了 2 个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)