Hello, i made this code today in my computer science lesson. I feel like I made too much use of if statements and I am not sure if there were any other things I couldve done to make it work. Any advice is appreciated π
import random
Credit = 100
Answer = input('Would you like to play the game? (y/n):')
while Credit > 0 and Answer == 'yes':
print(Credit)
Answer = input('Would you like to play the game? (y/n):')
if Answer != 'yes':
print('Okay, you are leaving with ', Credit , ' credits.')
break
Credit -= 20
Value1 = random.randint(1,4)
Value2 = random.randint(1, 4)
Value3 = random.randint(1, 4)
if Value1 == Value2 == Value3:
if Value1 == 1:
print('You got three lemons! +100 credit!')
Credit += 100
if Value1 == 2:
print('You got three cherries! +100 credit!')
Credit += 100
if Value1 == 3:
print('You got three Bells! +500 credit!')
Credit += 500
if Value1 == 4:
print('Unlucky! The game is over!')
Credit == 0
elif Value1 == Value2 or Value3 == Value2 or Value3 == Value1:
if Value1 == Value2 or Value1 == Value3:
if Value1 == 1:
print('You got two lemons! +50 credit!')
Credit += 50
if Value1 == 2:
print('You got two cherries! +50 credit!')
Credit += 50
if Value1 == 3:
print('You got two bells! +100 credit!')
Credit += 100
if Value1 == 4:
print('You got two skulls! Unlucky, -100 credit!')
Credit -= 100
if Value2 == Value3:
if Value2 == 1:
print('You got two lemons! +50 credit!')
Credit += 50
if Value2 == 2:
print('You got two cherries! +50 credit!')
Credit += 50
if Value2 == 3:
print('You got two bells! +100 credit!')
Credit += 100
if Value2 == 4:
print('You got two skulls! Unlucky, -100 credit!')
Credit -= 100
else:
print('You didn't win anything'.)