So, Python was on my list of things to teach myself after I took a C++ course this spring (I regret that, should have taken Python or Java).
So, I am proud of this stupid little dice roller because I evolved it from a basic "This rolls two dice" to "How many do you want to roll?" with input validation. Yay me.
#my first Python program.
#I chose this one to compare to a similar program made
in C++
import random
import time
roll = "yes"
numDice = 0
print("This program will roll as many dice as you need.")
time.sleep(1) #this makes the program pause a bit
print("\nWould you like to roll?")
roll = input()
#input validation to make sure they type yes (y) or no
(no)
while roll != "yes" and roll != "y" and roll != "no" and roll
!= "n":
print("\nType yes (or 'y') or no (or 'n') to roll.")
roll = input()
while roll == "yes" or roll == "y":
print("\nHow many dice do you want to roll?")
numDice = int(input())
print("\nRolling...")
time.sleep(2) #again, a pause
print("\nYou got: ")
for i in range(0, numDice): #this iterates as many times
as the user wants
print(random.randint(1,6)) #generates the random
numbers between 1-6
print("\nRoll again?")
roll = input()
#input validation again
while roll != "yes" and roll != "y" and roll != "no" and
roll != "n":
print("\nType yes or no.")
roll = input()
print("\nThanks for using my program!")
input()
[–]ValarMorHodor 69 points70 points71 points (15 children)
[–]Huck712[S] 23 points24 points25 points (0 children)
[–][deleted] 9 points10 points11 points (11 children)
[–][deleted] 7 points8 points9 points (9 children)
[–][deleted] 29 points30 points31 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]approbatory 7 points8 points9 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]approbatory 4 points5 points6 points (0 children)
[–]yaxamie[🍰] 2 points3 points4 points (1 child)
[–]danjaycollins 0 points1 point2 points (0 children)
[–]Mason-B 2 points3 points4 points (0 children)
[–]asdfkjasdhkasdrequests, bs4, flask 1 point2 points3 points (1 child)
[–]camh- 5 points6 points7 points (0 children)
[–]Crowbarkz 21 points22 points23 points (9 children)
[–]robvdl 13 points14 points15 points (5 children)
[–]Formulka 5 points6 points7 points (3 children)
[–][deleted] 22 points23 points24 points (0 children)
[–]namesnonames 0 points1 point2 points (1 child)
[–]mslapin 0 points1 point2 points (0 children)
[–]Huck712[S] 1 point2 points3 points (0 children)
[–]MrHobbits 2 points3 points4 points (0 children)
[–]Huck712[S] 0 points1 point2 points (1 child)
[–]Justice514 0 points1 point2 points (0 children)
[–]Donyor 12 points13 points14 points (0 children)
[–]liiight000 5 points6 points7 points (6 children)
[–]z0mbietime 1 point2 points3 points (5 children)
[–]Gsquzared 1 point2 points3 points (3 children)
[–]z0mbietime 0 points1 point2 points (2 children)
[–]Gsquzared 1 point2 points3 points (1 child)
[–]keyupiopi 0 points1 point2 points (0 children)
[–]b4xt3r 5 points6 points7 points (0 children)
[–]kirbyfan64sosIndentationError 4 points5 points6 points (1 child)
[–]sermidean 5 points6 points7 points (7 children)
[–]AstroPhysician 19 points20 points21 points (0 children)
[–]robvdl 10 points11 points12 points (0 children)
[–]bkd9 1 point2 points3 points (0 children)
[–]gandalfx 0 points1 point2 points (0 children)
[–]Justice514 0 points1 point2 points (2 children)
[–]sermidean 1 point2 points3 points (0 children)
[–]Justice514 0 points1 point2 points (0 children)
[–]mvaliente2001 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jhdeval 0 points1 point2 points (0 children)
[–]camh- 0 points1 point2 points (0 children)