python - Python Traceback(最近一次调用最后一次)错误
问题描述
我已经开始编码大约一个星期了,在练习创建形状计算器的过程中,我遇到了这样一个错误:
Traceback (most recent call last):
File "python", line 4
if option = 'C':
^
SyntaxError: invalid syntax
代码如下:
print "The Calculator has been launched"
option = raw_input ("What shape is your object? Enter C for circle or T
for Triangle.")
if option = 'C':
radius = float (raw_input ("What is the radius of your circle?") )
area_1 = 3.14159 * ( radius ** 2)
print area_1
elif option = 'T':
base = float (raw_input ("What is the base of the triangle?"))
height = float (raw_input ("What is the corresponding height of the
triangle?"))
area_2 = (base * height) * 1/2
print area
else :
print "Please, enter a valid shape"
如果有人能解释错误的原因,我将不胜感激。
谢谢!
解决方案
比较时必须使用==
. =
仅用于分配。
所以在你的例子中,这条线应该是
if option == 'C':
推荐阅读
- c - 将文件行存储在 char 双指针中的代码将同一行存储在所有元素中
- c# - '无法将'System.Security.Claims.ClaimsPrincipal'类型的对象转换为'TestApp.SecurityUser'类型。' 在 asp.net 核心中
- r - 将向量设置为月年 tsibble
- java - 如何限制某些传感器每隔几秒发送一次数据?
- c# - Admob 广告未在 Unity、C# 中显示
- linux - nohup 命令 & : 如何丢弃输出?
- c# - 为什么垃圾收集器不垃圾我的实例?
- sql-server - SELF JOIN 基于层次结构匹配行
- java - 前台服务类错误通知
- r - 是否有与 dplyr::coalesce() 相反的 R 函数?