I want to thank the person who suggested I work on handling invalid inputs and rolling multiple dice.
I want to learn how to code because it is my dream to get into the IT field, mainly cybersecurity, and I thought coding was the best place to start.
here is my code so far:
def main():
import random
import math
import time
ttshr = 0
try:
number_of_dice = int(input("how many dice do you want to roll: "))
except ValueError:
error_num_not_reconized = input('that is not a number i reconize would you like to try again? (y/n): ').lower()
if error_die_not_reconized == "y":
main()
else:
exit()
#asking what type of dice you what to roll
try:
type_of_die = int(input("what type of dice do you want to roll: "))
except ValueError:
error_die_not_reconized = input('that is not a dice i reconize would you like to try again? (y/n): ').lower()
if error_die_not_reconized == "y":
main()
else:
exit()
#confirming
print(f'{number_of_dice}d{type_of_die}, ok')
#rolling the dice just for flare
print("shakeing the dice for good luck")
time.sleep(5)
print("rolling the die")
time.sleep(2)
#displaying numbers
while ttshr == 0:
print(f'you got {random.randint(1, type_of_die)}', end=' ')
ttshr += 1
else:
while ttshr < number_of_dice:
print(f'{random.randint(1, type_of_die)}', end=' ')
ttshr += 1
else:
print(f'and {random.randint(1, type_of_die)}')
#if you want to do it again
do_it_again = input("do you want to roll again (y/n): ").lower()
if do_it_again == "y":
main()
else:
exit()
main()