input()
の結果は、ではなく、str
であり、乗算は文字列の意味が異なります。
>>> valin = input("How much would you like to bet?: ")
How much would you like to bet?: 20
>>> type(valin) # valin is a string!
<type 'str'>
>>> valin * 2 # multiplication will concatenate the string to itself
'2020'
>>> int(valin) * 2 # first convert it to an int, then multiply
40
あなたはlarsmansが示唆されているように行い、乗算前int
に変換する必要があります。ここでは一例です。ここにいくつかの特別な検証を加えたバージョンがあります:
print("You have chosen to bet on the even numbers")
while True:
try:
valin = int(input("How much would you like to bet?: "))
break
except ValueError:
print("Invalid input, please enter an integer")
print("If it lands on an even number, you win", valin*2)
何を試しましたか?あなたはそれを試したとき何が起こったのですか?あなたは何をしたいのですか?なぜそれが起こったと思いますか? –