1- #problem
2- #get a positive input from a user
3- #generate a random number between the number provided.
4- #Prompt user to guess the number ( a posivie integer)
5- #if it's less, Print too small! and reprompt the user
6- #if it's too big, print too large! & reprompt the user
7- #if the guess is right, print Just right! and break
8-
9-
10- #My solution
11-
121from random import randrange
13-
14- # Prompt the user for an input - a positive integer & randomize the input
15- # Prompt the user again for an input called guess - a positive integer
16- # Check if the user guess is the same has the randomized result.
17- # if yes, print just right else print too small or too big if it's too small or too big & reprompt the user to
18- # guess the randomized result again.
19-
202def main ():
213 randomized_no = randomize_no ()
224 while True :
@@ -30,8 +12,6 @@ def main():
3012 else :
3113 print ("Just right!" )
3214 break
33-
34- # make sure whatever the user inputted is a positive integer.
3515def is_positive_integer (n ):
3616 """This function takes an input and check if the user input is an integer"""
3717 while True :
@@ -43,28 +23,18 @@ def is_positive_integer(n):
4323 return False
4424 else :
4525 return True
46-
47- #Prompt the user for an input and check if what user inputted is a positive interger
48-
4926def get_user_input ():
5027 """Prompt the user for an input and check if it's a positive integer"""
5128 while True :
5229 user_input = input ("Level 1: " )
5330 if (is_positive_integer (user_input )):
5431 return int (user_input )
55-
56-
57- #Prompt the user to guess and check if that number is a positive integer.
5832def guess ():
5933 "Prompt the user for an input guess, and check if it's an integer"
6034 while True :
6135 user_guess = input ("Guess: " )
6236 if is_positive_integer (user_guess ):
6337 return user_guess
64-
65-
66- # call get_user_input which collects an input from user and check if it's an integer
67- # Randomize the number collected from the get_user_input function and return it.
6838def randomize_no ():
6939 """Randomize number"""
7040 user_inputted_number = get_user_input ()
@@ -73,20 +43,5 @@ def randomize_no():
7343 return random_number
7444 else :
7545 return int (user_inputted_number )
76-
7746if __name__ == "__main__" :
7847 main ()
79-
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
91-
92-
0 commit comments