TypeError:create_purple()需要0个位置参数,但有2个被给出
问题描述:
我是Python编程的新手,并试图使这个程序工作。TypeError:create_purple()需要0个位置参数,但有2个被给出
我已经通过使用“if”和“else”语句使这个程序工作,但是,我想用下面的方法制作这个程序。当我运行程序时,我不断收到一个错误“TypeError:create_purple()需要0个位置参数,但2个给出”,我不明白为什么。
这里是我的代码:
#*******************************************************************************************
#
# 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 ('\n')
# Tell the user the objective of the program.
print ('*****************************************************************************')
print ('*****************************************************************************')
print ('\n')
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 ('\n')
print ('You have made the color.... Purple ')
else:
if color1 == BLUE and color2 == RED:
print ('\n')
print ('You have made the color.... Purple ')
# Call the main function
main()
答
要调用以2个参数create_purple,但你的定义(DEF)有0参数。
简单地更新定义:
def create_purple(color1,color2):
我恨我这样做的时候 - 我想通了就在我张贴的问题。我需要在def create_purple():行中插入“color1,color2”。它应该读取... def create_purple(color1,color2): – 2014-10-01 14:53:52