Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Сумиране до число (while)
- # Въведете положително цяло число n.
- # Използвайте while, за да изчислите сумата на числата от 1 до n.
- num = int(input("Please enter a positive integer: "))
- i = 1
- sum_num = 0
- if num < 0:
- while num < 0:
- print("Enter a positive integer: ")
- num = int(input())
- if num > 0:
- while i <= num:
- sum_num += i
- i += 1
- if sum_num != 0:
- print("Тhe sum of the numbers from 1 to " + str(num) + " is: " + str(sum_num))
- else:
- print("Тhe sum is 0")
Advertisement
Add Comment
Please, Sign In to add comment