forked from wbhoomika/python4beginners-Hacktoberfest22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom_number.py
41 lines (40 loc) · 1.43 KB
/
Random_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from random import randint
name = input("Please Enter your name: ")
print("Welcome to my Number game, " + name)
def game():
rand_number = randint(0,100)
print("\nI have selected a number between 1 to 100...")
print("You have 6 chances to guess that number...")
i = 1
r = 1
while i<7:
user_number = int(input('Enter your number: '))
if user_number < rand_number:
print("\n" + name + ", My number is greater than your guessed number")
print("you now have " + str(6-i)+ " chances left" )
i = i+1
elif user_number > rand_number:
print("\n" + name + ", My number is less than your guessed number")
print("you now have " + str(6-i)+ " chances left" )
i = i+1
elif user_number == rand_number:
print("\nCongratulations "+name+"!! You have guessed the correct number!")
r = 0;
break
else:
print("This is an invalid number. Please try again")
print("you now have " + str(6-i)+ " chances left" )
continue
if r==1:
print("Sorry you lost the game!!")
print("My number was = " + str(rand_number))
def main():
game()
while True:
another_game = input("Do you wish to play again?(y/n): ")
if another_game == "y":
game()
else:
break
main()
print("\nEnd of the Game! Thank you for playing!")