0
私は計算のためのユーザー入力を使いたいと思いますが、add(* args)とsub(* args)を定義していますが、if文のadd()で* argsを書くとそのshow error:argsは定義されていません mは、そのは、mの値ではない合計私を示して....if文のadd()とsub()でパラメータとして使うべきものは何ですか?
def add(*args):
total = 0
for a in args:
total += a
print(total)
def sub(*args):
total = 0
for a in args:
total -= a
print(total)
print('1-add\n2-sub')
n=int(input("enter choice:"))
counter = int(input("enter no of No.to be calculated:"))
if n == 1:
for i in range(counter):
m=int(input("enter no."))
add()
elif n == 2:
for i in range(counter):
m = int(input("enter no."))
sub()
else:
print("invalid")
しかし、どのように最後の「場合のn == 1で、リストを追加する: アドオン(int型(elif n == 2: sub(int(入力)(範囲内)) ' – Trunks
@Trunksわかりません。このアプローチを使用する場合、 'append'を使う必要はありません。 「追加」するリストはありません。 – DeepSpace