【问题标题】:Syntax error within IF commandIF 命令中的语法错误
【发布时间】:2018-05-08 19:41:28
【问题描述】:
print ('Here are the availible currency choices for today:')  
currencylist = ['US Dollar','Kenyan Shilling','Brazilian Real','Canadian 
Dollar','Indian Rupee','Philippine Peso','Indonesian Rupiah']  
print(*currencylist, sep='\n')  
currency= input(str('Which currency would you like to choose? '))  
pound= input(float('Please enter the amount you would like to exchange. £')  
if currency == ('US Dollar')  
    rate= 1.52  
    print rate

当我尝试定义 rate 变量时,我不断收到语法错误。有什么想法吗?

【问题讨论】:

  • 这是什么语言? Python?您应该在帖子中添加特定于语言的标签。您的if 语句末尾似乎缺少:
  • 欢迎来到 StackOverflow。假设这是 Python,请在您的帖子中添加 python 标签,以便吸引合适的人,我们确定您使用的是什么语言。此外,将来,请始终发布错误消息。但我敢打赌,这只是缺少的冒号。如果是这种情况,请在评论中告诉我们。

标签: if-statement syntax


【解决方案1】:

你用这个

if (currency == 'US Dollar')  {

    rate= 1.52  
    print rate
}

【讨论】:

  • 然后使用克隆:
【解决方案2】:

if 需要在条件末尾有一个冒号:

if currency == 'US Dollar': rate = 1.52

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    相关资源
    最近更新 更多