I just fit into Python coding and I wonder what is considered more pythonic? Example A: The obvious basic method.
#!/usr/bin/env python -tt import random def dice_roll(num=1): for _ in range(num): print("Rolled a", random.randrange(1,7,1)) def main() random.seed() try: num = int(input("How many dice? ")) dice_roll(num) except ValueError: print("Non-numeric Input") if __name__ == '__main__': main()
or Example B: There is no basic method.
#!/usr/bin/env python -tt import random def dice_roll(num=1): for _ in range(num): print("Rolled a", random.randrange(1,7,1)) if __name__ == '__main__': random.seed() try: num = int(input("How many dice? ")) dice_roll(num) except ValueError: print("Non-numeric Input")
Any tips / pointers would be appreciated?
source share