Ok, I need some help here. I’m attempting to write a program that rolls a die internally (randrange), which is referenced to a list that will then print the result onto the screen
Example: User inputs “1”, activating the dice roll. The program rolls a 2 and checks a list to see what 2 means. 2 means Medium, so it then prints “Medium”
However, I can’t figure out where I’d look for a tutorial on this (as I can’t figure out what I’d even search for), and everyone I ask gets confused by the question. So I come to you with a pasted set of code. Here’s a pastebin for better viewing: http://pastebin.com/PGEmNqTm
import random
def Main() :
print TESTING
print
print
print "1 1d4"
sum = raw_input("> ")
if sum == '1':
numberr = random.randrange(1, 5)
if numberr = 1
print "Small"
elif numberr = 2
print "Medium"
elif numberr = 3
print "Large"
elif numberr = 4
print "Huge"
while 1:
input = raw_input("Press Enter to continue or q to quit").upper()
if input == 'Q': break
elif input == '' : Main()
Aside from a few small details, your code seems pretty good as it is.
Those are:
Your
if numberr == x:lines shouldn’t be indented because they’re not part ofa new block.
You need to double the
=sign when doing a test:if number == 1:You need a colon for an
if(which you knew, but it was missing on somelines).
raw_inputnotraw_imputQuotes around “TESTING”
Here’s the code with those fixes:
So I’d say you already seem to have it right.
(Also Vishal’s advice is good too)