本文介绍了python中的加减法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在做一个 statcalc,除了添加之外,一切都在工作.当我选择添加它的选项时,只是跳过它并说选择一个选项.我想知道这是怎么回事?

So I am making a statcalc and everything is working except adding. When I select the option to add it just skips it and says select an option. I was wondering what's wrong with it?

numberstoadd = input("What is the first number you want to add? ")
numbertoadd = input("What do you want to add to it? ")
sum = numbertoadd + numberstoadd
print sum

推荐答案

您需要将输入的 strings 转换为 ints.像这样:

You need to turn your input strings into ints. Like this:

number_1 = int(raw_input("What is the first number you want to add? "))
number_2 = int(raw_input("What do you want to add to it? "))
sum = number_1 + number_2
print sum

这篇关于python中的加减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:19