MCPcopy Create free account
hub / github.com/geekcomputers/Python / get_integer

Function get_integer

Sum of digits of a number.py:6–23  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5
6def get_integer():
7 for i in range(
8 3, 0, -1
9 ): # executes the loop 3 times. Giving 3 chances to the user.
10 num = input("enter a number:")
11 if num.isnumeric(): # checks if entered input is an integer string or not.
12 num = int(
13 num
14 ) # converting integer string to integer. And returns it to where function is called.
15 return num
16 else:
17 print("enter integer only")
18 print(
19 f"{i - 1} chances are left"
20 if (i - 1) > 1
21 else f"{i - 1} chance is left"
22 ) # prints if user entered wrong input and chances left.
23 continue
24
25
26def addition(num):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected