You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3中调用Corner函数时出现Invalid Syntax Error求助

解决Python3中print语句的SyntaxError问题

Hey there! Let's break down and fix that syntax error you're hitting.

问题根源

The error SyntaxError: invalid syntax on line print Corner(6) happens because in Python 3, print is a built-in function, not a statement. In Python 2, you could write print something without parentheses, but Python 3 strictly requires function call syntax with parentheses for print.

Plus, a small side note: your Corner function already includes print statements inside it, so its return value is None. If you just fix the syntax to print(Corner(6)), you'll end up with your intended output plus an extra None printed (since you're printing the function's return value), which is probably not what you want.

修正后的代码

Here are two solid fixes, pick the one that fits your needs:

  1. 直接调用函数(推荐)
    Since the function handles printing on its own, you just need to call it directly:
def Corner(n):
    if n == 3:
        print('Its A Triangle \nBu Bir Üçgen')  # 修正了小拼写错误:İts → Its,An → A
    elif n == 4:
        print('Its A Rectangle or Square or Parallelogram \nBu Bir Dikdörtgen yada Kare yada ParalelKenar ')
    elif n == 5:
        print('Its A Pentagon \nBu Bir Beşgen')
    elif n == 6:
        print('Its A Hexagon \nBu Bir Altıgen')
    else:
        print('Bir Köşe Sayısı Girmediniz \nYou Didnt Wrote a Corner Number ')

# 直接调用函数,无需额外print
Corner(6)
  1. 让函数返回字符串,外部打印(更灵活)
    If you want to reuse the output text elsewhere later, have the function return the string instead of printing it:
def Corner(n):
    if n == 3:
        return 'Its A Triangle \nBu Bir Üçgen'
    elif n == 4:
        return 'Its A Rectangle or Square or Parallelogram \nBu Bir Dikdörtgen yada Kare yada ParalelKenar '
    elif n == 5:
        return 'Its A Pentagon \nBu Bir Beşgen'
    elif n == 6:
        return 'Its A Hexagon \nBu Bir Altıgen'
    else:
        return 'Bir Köşe Sayısı Girmediniz \nYou Didnt Wrote a Corner Number '

# 调用函数并打印返回值
print(Corner(6))

验证效果

Run either version, and when you pass 6, you'll get the expected output without any syntax errors:

Its A Hexagon 
Bu Bir Altıgen

内容的提问来源于stack exchange,提问作者M_Ouz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:24:27