python字符串迭代_Python字符串迭代/函数

我需要我的“items”变量将每个项目打印到新行上。我总是在“items”中得到总数,在“total”中得到总数。“总计”打印出我想要的结果,但我希望这些项目单独打印。在

有什么想法?在def adding_report():

user_input = input("Report Types include All Items ('A') or Total Only ('T')\nChoose Report Type ('A'or'T'):")

items = "\n"

total = 0

while True:

if user_input == 'A'.lower():

user_input1 = input("Input an integer to add to the total or 'Q' to quit: ")

if user_input1.isdigit():

items = int(user_input1)

total += int(user_input1)

continue

elif user_input1 == 'Q'.lower():

print("Items\n", items)

print("Total\n", total)

break

elif user_input1.startswith('q'):

print('Items\n', int(items))

print("Total\n", total)

break

else:

print("Input is not valid")

elif user_input == 'T'.lower():

user_input2 = input("Input an integer to add the total or 'Q' to quit: ")

adding_report()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值