1
1
import random
2
- num = random . randint ( 1 , 9 )
3
- player_name = input ("Hello mate , What's your name ?\n " )
2
+ player_name1 = input ( "Hello player 1, What's your name? \n " )
3
+ player_name2 = input ("Hello player 2 , What's your name?\n " )
4
4
guess_count = 0
5
- print ("welcome " , player_name , ", are you ready to plat the guessing game ? (yes/no)" ), a = input ()
6
- if a == "yes" :
7
- print ("I'm guessing a number between 1 to 9" )
8
- while guess_count < 5 :
9
- guess = int (input ())
5
+ print ("welcome " , player_name1 , "and" , player_name2 , ",this is the number guessing game." )
6
+ p1_points = 0
7
+ p2_points = 0
8
+ while True :
9
+ num = random .randint (1 , 9 )
10
+ print (player_name1 , "type your guess." )
11
+ g1 = int (input ())
12
+ print (player_name2 , "type your guess." )
13
+ g2 = int (input ())
14
+ if g1 == num :
15
+ print ("Hurray" , player_name1 , ",you guessed it right!" )
16
+ p1_points += 1
17
+ else :
18
+ print ("Sorry" , player_name1 , ',you guessed it wrong.' )
19
+ if g2 == num :
20
+ print ("Hurray" , player_name2 , ",you guessed it right!" )
21
+ p2_points += 1
22
+ else :
23
+ print ("Sorry" , player_name2 , ',you guessed it wrong.' )
10
24
guess_count += 1
11
- if guess < num :
12
- print ('Your guess is too low' )
13
- if guess > num :
14
- print ('Your guess is too high' )
15
- if guess == num :
16
- print ("Hurray, you guessed it right!" )
17
- print ('You guessed the number in ' + str (guess_count ) + ' tries!' )
18
- break
25
+ print ("The right number is" , num , "." )
26
+ cont = input ("Do you both wish to play again? If yes then type 'yes'.\n " )
27
+
28
+ if cont != 'yes' :
29
+ print ('Thank you for playing.' )
30
+ print (player_name1 , ", you had" , p1_points , "right out of" , guess_count , "." )
31
+ print (player_name2 , ", you had" , p2_points , "right out of" , guess_count , "." )
32
+ if p1_points > p2_points :
33
+ print (player_name1 , ", you won the game." )
34
+ elif p1_points < p2_points :
35
+ print (player_name2 , ", you won the game." )
19
36
else :
20
- print ('You did not guess the number, The number was ' + str (num ))
21
- else :
22
- print ("hoping to see you soon again! :)" )
37
+ print ("Both have same points, so that's a tie." )
38
+ break
0 commit comments