私は非負整数の形でユーザー入力を収集しようとしています。私はこの整数を取って、その整数にある奇数、偶数、およびゼロの1桁の数字の数をユーザーに伝えたいと思います。文字列から1桁の数字を読み取って関数を実行する方法は?
Ex。ユーザー入力 "123"とプログラム出力Evens:1奇数:2零点:0
これまでのコードです。
def main():
print("1. Enter a new number")
print("2. Print the number of odd, even and zero digits in the integer")
print("3. Print the sum of the digits of the integer")
print("4. Quit the program")
value = (input("Please enter a non-negative integer"))
Sum = 0
evens = 0
odds = 0
zeros = 0
loop=True
while loop:
main()
choice = int(input("Enter a number between 1 and 4:"))
if choice==1:
loop=False
value = int(input("Please enter a non-negative integer"))
loop=True
elif choice==2:
loop=False
value_string = str(value)
for ch in value_string:
print(ch)
for [1] in value:
if i % 2 == 0:
evens = evens + 1
print(evens)
elif choice==3:
loop=False
while (value >0):
remainder = value % 10
Sum = Sum + remainder
value = value //10
print("Sum of the digits = %d" %Sum)
[1] in value: 'にはかなりの数の問題があります。 –
インデント –
を再度入力し、ボタン{}}を使用してSOのコードを正しくフォーマットしてください。 – furas