python多次输出同行_Python打印函数多次输出

我正在制作一个程序来完成certain python challenge。我创建了这个程序,它基本上完成了我需要它做的一切,除了它有一个奇怪的怪癖;它打印我想要的输出多次。在cmdname = input("Enter the name of your command.\n>")

print("Enter options one by one. If the option has an argument, put a * at the end of the option. When done entering options, enter \"q\".")

oplist = ""

oplist += cmdname + " "

def prgm():

global oplist

while 2 + 2 == 4:

user = input(">")

if user[0] == "-":

if "*" in user:

oplist += user[0:len(user) - 1] + " "

print("Now, enter the option's argument.")

user = input(">")

oplist += user[0:len(user) - 1] + " "

print("Option successfully added.")

prgm()

else:

oplist += user + " "

print("Option successfully added.")

prgm()

elif user == "q":

print("Enter the command argument.")

user = input(">")

oplist += user

else:

print("Error. You didn't enter an option.")

prgm()

break

print(oplist)

prgm()

输出的打印次数似乎取决于用户指定了多少个选项,但我不知道为什么。另外,在IDLE中运行程序时,如果我在函数完成后手动打印(oplist),IDLE会像我希望的那样在一行上打印一次输出。为什么会这样?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值