首页 > 解决方案 > How to calculate the total of all the number between 1 and the number that the user entered?

问题描述

I have to ask the user to enter an integer number and the program will calculate the total of all the number between 1 and the number that the user entered. For example, if I enter 5 and the output will be The total is 15

标签: pythonpycharm

解决方案


接受用户输入。分配total = 0然后循环

   num = int(input("Enter number: "))

    tot = 0

    for i in range(num + 1):
        tot += i

    print(tot)

推荐阅读