これはパイソンです。グローバル変数を使用せずにユーザーに文字列入力を求めるプログラムを作成しようとしています。文字列にかっこが並んでいるだけの場合、それは偶数です。文字、数字が含まれている場合、または括弧が間隔を空けて配置されている場合は、不均一です。たとえば、() と ()() と (()()) は偶数ですが、(() と (pie) と ( ) はそうではありません。以下は私がこれまでに書いたものです。私のプログラムは印刷を続けます 'あなたの文字列を無限に入力してください、私は今その問題に悩まされています。
selection = 0
def recursion():
#The line below keeps on repeating infinitely.
myString = str(input("Enter your string: "))
if not myString.replace('()', ''):
print("The string is even.")
else:
print("The string is not even.")
while selection != 3:
selection = int(input("Select an option: "))
#Ignore this.
if selection == 1:
print("Hi")
#This won't work.
elif selection == 2:
def recursion():
recursion()