私はちょうど(これで全く新しい)コード方法を学び始めたので、Pythonを使うことに決めました...私はx + yを追加して結果を与える関数を使いたいと思っていますが、x + yとxの和ではなく、その2つの数字。例えば。 1 + 1 = 11(2の代わりに)Pythonは数値を合計していないので、それらを一緒に貼り付けます
以下はコードです。私が間違っていることを教えてください。 !おかげで〜 (はい、私は本を使用していますが、それは何らかの形での説明にあいまいです[Pythonのに苦労して学ん])
def add(a, b):
print "adding all items"
return a + b
fruits = raw_input("Please write the number of fruits you have \n> ")
beverages = raw_input("Please write the number of beverages you have \n> ")
all_items = add(fruits, beverages)
print all_items
はFYI、本は私を与えたコードはでした:
def add(a, b):
print "ADDING %d + %d" % (a, b)
return a + b
def subtract(a, b):
print "SUBTRACTING %d - %d" % (a, b)
return a - b
def multiply(a, b):
print "MULTIPLYING %d * %d" % (a, b)
return a * b
def divide(a, b):
print "DIVIDING %d/%d" % (a, b)
return a/b
print "Let's do some math with just functions!"
age = add(30, 5)
height = subtract(78, 4)
weight = multiply(90, 2)
iq = divide(100, 2)
print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq)
# puzzle
print "Here is a puzzle."
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
print "that becomes: ", what, "Can you do it by hand?"
これは、 'raw_input()'に入れたものが文字列であるため、このように張られているはずです。それを確認して整数に変換する –
'raw_input'は、入力を文字列形式でint型に変換する必要があります。つまり、' fruits = int(raw_input( "果物の数を書きなさい\ n>")) ' –
manそれは速い応答だった、ありがとう、私の問題を解決した多くのおかげで、私は本当に整数を使用する方法を教えてhavent(私はそれが完全に理解していなかったので非常に曖昧だった..)歓声:) –