2021-03-20 16:16:45
Hope, you guys learnt well from last post So, in this post i am giving source code of an awesome game which i still play in my school
first let me explain about while loops:
The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true. We generally use this loop when we don't know the number of times to iterate beforehand.
In simple words, it gonna relate to the normal english and generally used when we just don't know the number of time to iterate
Name - Handcricket
import random
balls = 0
count = True
total = 0
totl = 0
count = 1
while (count, balls, 1):
user = int(input("Enter number from 1 to 10 \n"))
print("You've inputed", user, "\n")
User2 = (random.randint(1, 10))
print("PLAYER2 choose", User2, "\n")
#LOST
if (User2 == user):
print("Your Innings OVER. PLAYER2 also choose a", User2, "\n")
break
if(user > 10):
print("You Should select 1-10")
print("YOU ARE OUT")
print("PLAYER2's BATTING")
break
if (user < 1):
print("You Should select 1-10")
print("YOU ARE OUT")
print("PLAYER2's BATTING")
break
else:
total = total + user
print("Your total is now", total)
while (count, balls, 1):
user = int(input("Enter number from 1 to 10 \n"))
print("You've inputed", user, "\n")
User21 = (random.randint(1, 10))
print("PLAYER2 choose", User21, "\n")
#WON
if(user == User21):
print("PLAYER2 is OUT", "\n")
break
else:
totl = totl + User21
print("PLAYER2 total is now", totl)
SAVE IT AS ANYNAMEYOUWANT.py
and play this awesome game
and modify it with your own ideas
Here you can see the proper implement of basics of random module
ENJOY
SHARE AND SUPPORT US
CREDITS - @Nileshbansal24
816 views13:16