+ 1

Any advice or suggestions regarding this code.

#A Ludo Dice """ The code will roll a random between 1 - 6. If rolled value is 6, then the dice will roll again, if it rolls 6 the second time, it rolls again. But if it rolls 6 the third time it'll say 'oops'. Enjoy! and any advice or suggestion is highly appreciated. """ import random min = 1 max = 6 value = (random.randint(min,max)) print(value) while (value) == max: print("Rolling again...") value = (random.randint(min,max)) print(value) if value == max: print("Rolling again...") value = (random.randint(min,max)) print(value) if value == max: print("Oops") else: print("Nice Roll")

4th Aug 2020, 10:45 AM
Thrishong Sherpa
Thrishong Sherpa - avatar
3 Antworten
+ 2
Well, your code is repetitive. You could put the handling into a function and work with a "rolls" counter and a dictionary for the various messages.
4th Aug 2020, 3:34 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
You're welcome, I repeated myself too as a beginner 😉👍 I'd say we all did... And it's completely okay to do so and clean this up afterwards, if it's making a process flow clearer for the moment.
4th Aug 2020, 3:49 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Sandra Meyer thanks for your advice...i realize this code is a complete abomination of the DRY principal...😂😂...but with my current level of proficiency...this was the best i could do..but will definitely take ur advice to heart and improve in the future. 😬
4th Aug 2020, 3:45 PM
Thrishong Sherpa
Thrishong Sherpa - avatar