Can you please help me with my code? I am very fresh in python and coding in general. My code works well when the number randomly generated is greater then "1". How do I re-run the functions until the number generated is greater then "1"?
My code is:
from random import randint
def dice_roll_input():
'''
Askes the user to type "roll" to run the function that
simulates rolling the dice.
'''
print('Roll more then "1" to kill the python.\n')
dice_conf = input('Type "roll" to roll the dice\n')
if dice_conf == 'roll':
return
if dice_conf != 'roll':
dice_roll_input()
def roll_dice():
'''
Simulates rolling the dice and returning the result.
'''
random_dice = randint(1,6)
return random_dice
def kill_python(dice):
'''
Based on the dice roll, either python gets killed or
it dodges the attack and user needs to roll again.
'''
if dice == 1:
print(f'You rolled: {dice} \n')
print('Python dodged your attack. Try again.\n')
else:
print(f'You rolled: {dice} \n')
print('You killed the python!')
def attack_python():
'''
Function to loop through dice rolls until dice>1.
'''
dice = 1
while dice == 1:
dice_roll_input()
dice = roll_dice()
kill_python(dice)
def main():
"""
Run all program functions
"""
attack_python()
main()