Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
My first Python program :) (I'm hooked)

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()


/r/Python
https://redd.it/6hmq58