我是Python编程的新手,并试图让这个程序工作。
我已经使用"使这个程序工作了。如果"和"否则"但是,我想用以下方法制作相同的程序。当我运行程序时,我不断收到错误" 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()
答案 0 :(得分:1)
您正在调用带有2个参数的create_purple,但您的定义(def)有0个参数。
只需更新定义:
def create_purple(color1,color2):