Python:使用循环和用户输入来运行程序,直到提示终止

问题描述 投票:0回答:1
我在早期的编码任务上遇到了麻烦。除了教授了一个循环的基础知识外,没有任何与此目的有关的目的。

def branching_looping(): while True: x=[1,2,3,4,5,6,7,8,9,10] for i in x: print(i) y=1 for y in range(10): print(f"{y+1}") #Array can be automatically generated by giving its length. To avoid an output of 0, add one to starting value. n = int(input("Please define n:")) count = n total = 0 while count: total += count count -= 1 print(f"The sum of the range of {n} is {total}") #Repeatedly adds the current value, subtracts one from the current value, then adds the resulting value again. z=int(input("Please input number:")) if z //2 is int: z=False else: z=True print("This is an odd number!") terminate=input("Would you like to exit the program? y/n:") if terminate=="y": print("Goodbye!") break else: print("From the top, then!")

添加最后一个输入提示和相关的IF-ELSE语句时,一切都会中断。终端不会给我任何输入提示,而只是显示输入的任何内容。
我尝试在循环之前和内部定义和调用功能,但无济于事。 我知道我在这里还有其他问题。我特别正在寻找有关如何使用用户输入终止循环的答案。

没有什么....

# # as floats # x=15.0 y=2.0 print(f'x:{x}, y:{y} , x//y==:{x//y} x%y=={x%y} type(x//y):{type(x//y)}, type(x%y):{type(x%2)}') x:15.0, y:2.0 , x//y==:7.0 x%y==1.0 type(x//y):<class 'float'>, type(x%y):<class 'float'> # # as integers # x=15 y=2 print(f'x:{x}, y:{y} , x//y==:{x//y} x%y=={x%y} type(x//y):{type(x//y)}, type(x%y):{type(x%2)}') x:15, y:2 , x//y==:7 x%y==1 type(x//y):<class 'int'>, type(x%y):<class 'int'>

python loops while-loop terminate
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.