简体   繁体   English

正确缩进所有内容时出现python计算器语法错误

[英]python calculator syntax error when everyting is indented correctly

math = raw_input("Addition + or multiplication *.")

numbers = int(raw_input("How many numbers would you like to use?")

numbers_list = []

for input in range(numbers):
    new_number = float(raw_input("Enter your numbers.")
    numbers_list.append(new_number)

if math == "+":
    print sum(new_number)

if math == "*":
    import numpy
    product = numpy.product(numbers_list)
    print (product)

Close the brackets that was not closed关闭未关闭的括号

And properly indent the code并正确缩进代码

math = raw_input("Addition + or multiplication *.")

numbers = int(raw_input("How many numbers would you like to use?"))

numbers_list = []

for input in range(numbers):
    new_number = float(raw_input("Enter your numbers."))
    numbers_list.append(new_number)

if math == "+":
    print sum(new_number) # throws error TypeError: 'float' object is not iterable, so it should be
    #print sum(numbers_list)

if math == "*": 
    import numpy 
    product = numpy.product(numbers_list)
    print (product)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM