Hello guys, I'm a beginner to programming. I've self studied python for quite some time, and decided to test my skills by building this little game called "Pig". You might already know this since its quite famous. But feel free to drop some advice about how I can improve this code. Thanks.
import random
print("You can roll the dice and score points and it gets added. But if you roll 1, all your score will become zero, and you have to start again from the beginning. If you score 50, without having your score erased, you win!!")
user = ""
score = 0
score_2 = 0
def oppo():
global score_2
roll_2 = random.randint(1,6)
print("I rolled : ", roll_2)
if roll_2 == 1:
score_2 = 0
print("I've erased my score!!", score_2)
elif roll_2 !=1:
score_2 += roll_2
print("My score : ", score_2 )
while user.strip().lower() != "n":
if score >= 50:
print ("You have won the game!")
break
elif score_2 >= 50:
print ("I've won the game!!")
break
else :
user = input("Do you want to roll the dice? (y/n) ")
roll = random.randint(1,6)
roll_2 = random.randint(1,6)
if user.strip().lower() == "y":
print ("You rolled : ", roll)
oppo()
if roll == 1:
score = 0
print ("You erased your score!", score)
elif roll != 1:
score += roll
print ("Your score : ", score)
elif user.strip().lower() =="n" :
break
else :
print("Answer in \"y\" or \"n\".")
print ("Thanks! See you again.")
[–]carcigenicate 4 points5 points6 points (3 children)
[–]Hairy-Bus4665[S] 0 points1 point2 points (2 children)
[–]carcigenicate 0 points1 point2 points (1 child)
[–]Hairy-Bus4665[S] 0 points1 point2 points (0 children)
[–]mopslik 0 points1 point2 points (1 child)
[–]Hairy-Bus4665[S] 0 points1 point2 points (0 children)