Hi,
I've found a nice tutorial which I've already started.
I'd like to now how could my solutions be better, let's say more pytonic. I'm really into python, I'd like to have strong foundation, while learning it.
Please if you have time, and can provide clearer, easier, more pythonic code, please share it with me.
1. Dice Rolling Simulator version A:
I've found a nice tutorial which I've already started.
I'd like to now how could my solutions be better, let's say more pytonic. I'm really into python, I'd like to have strong foundation, while learning it.
Please if you have time, and can provide clearer, easier, more pythonic code, please share it with me.
1. Dice Rolling Simulator version A:
import random import time def castDie(): input('Press any key to cast the die!') r = list(range(1, 7)) print('Result: ' + str(random.choice(r))) while True: time.sleep(1) castDie()1. Dice Rolling Simulator version B:
import random def question(): input('Press enter to roll!') def roll(): n = [1, 2, 3, 4, 5, 6] print(random.choice(n)) question() roll()2. Guess The Number:
import random n = random.randrange(1, 101) print('I\'ve though a number between 1 and 100!') while True: try: g = input('Guess!') g = int(g) if not 100 > g > 0: print('It\'s in between 0 and 100!') except ValueError: print('Enter an integer') continue if g == n: print('Congratulations!') break if g < n: print('Larger') if g > n: print('Smaller')