Python 使用if";x";在函数中进行计算器运算,但总计不';不生产

Python 使用if";x";在函数中进行计算器运算,但总计不';不生产,python,Python,我是Python的新手,我的代码有问题,我使用if in函数来做蔬菜水果商的计算器,当输入三个苹果被购买时,总产量为0英镑,而它应该是3.90英镑 total = 0 print "Welcome to the green grocers, what would you like?" print "1. Apples" print "2: Bananas" print "3. Oranges" print "4. Total" fruit = raw_input("What would

我是Python的新手,我的代码有问题,我使用if in函数来做蔬菜水果商的计算器,当输入三个苹果被购买时,总产量为0英镑,而它应该是3.90英镑

total = 0


print "Welcome to the green grocers, what would you like?"
print "1. Apples"
print "2: Bananas"
print "3. Oranges"
print "4. Total"



fruit = raw_input("What would you like?")

if "1" in fruit:
   q = input("How many?")
   total + (q*1.3)
   fruit = raw_input("What would you like?")

if "2" in fruit:
   g = input("How many?")
   total + (g*1.5)
   fruit = raw_input("What would you like?")

if "3" in fruit:
   l = input("How many?")
   total = (l*1.6)
   fruit = raw_input("What would you like?")

   if "4" in fruit:
   print "Your total is £", total
你需要:

total = total + (q*1.3)
或:

整数是不可变的,只需执行
total+(q*1.3)
不会影响
total
,它只会返回一个新的整数

>>> x = 1
>>> x + 2   # Simply returns a new value, doesn't affects `x`
3
>>> x       # `x` is still unchanged
1
>>> x += 1  # Assign the new value back to `x`
>>> x       # `x` is now updated.
2
你需要:

total = total + (q*1.3)
或:

整数是不可变的,只需执行
total+(q*1.3)
不会影响
total
,它只会返回一个新的整数

>>> x = 1
>>> x + 2   # Simply returns a new value, doesn't affects `x`
3
>>> x       # `x` is still unchanged
1
>>> x += 1  # Assign the new value back to `x`
>>> x       # `x` is now updated.
2

您正在执行计算,但未更新
总计
变量。这样做:

total = total + (g*1.5)
或使用
+=
运算符:

total += g*15

希望这有帮助

您正在执行计算,但未更新
total
变量。这样做:

total = total + (g*1.5)
或使用
+=
运算符:

total += g*15

希望这有帮助

如果水果中的“4”为“”,您还需要将缩进的代码块放在“
下:
或删除该行。为什么有人对此投了反对票?他说他是个新手。这个问题被精心编辑。我不明白为什么应该被否决。如果水果中的“4:或删除该行,您还需要在
下放置一个缩进的代码块。为什么有人否决了这个?他说他是个新手。这个问题被精心编辑。我不明白为什么要被否决。