Code import random
def five():
reroll = True
while reroll:
roll = random.randint(1,100)
print('You rolled a',roll)
if roll >= 55:
print('You rolled over 55! You win!')
else:
print('Sorry, you rolled under 55, you lose!')
print('Do you want to reroll? If yes enter "y" or "yes", if not "n" or "no"')
reroll = ("y" or "yes") in input().lower()
five()
If anyone has any ideas how I could make it better then please let me know!
Hopefully someone can find this useful
(Oct 6, 2017 07:12 AM)Will Patterson Wrote: Code import random
def five():
reroll = True
while reroll:
roll = random.randint(1,100)
print('You rolled a',roll)
if roll >= 55:
print('You rolled over 55! You win!')
else:
print('Sorry, you rolled under 55, you lose!')
print('Do you want to reroll? If yes enter "y" or "yes", if not "n" or "no"')
reroll = ("y" or "yes") in input().lower()
five()
If anyone has any ideas how I could make it better then please let me know!
Hopefully someone can find this useful
I would keep functions to a Single responsibility as per https://en.wikipedia.org/wiki/Single_res..._principle
PHP Code
<?php from random import randint
def roll(): roll = randint(1,100) print('You rolled ', roll) return roll def check(n): if n > 55: return True else: return False
def main(): while True: if check(roll()): print('You rolled over 55 you win!') else: print('Sorry, you rolled under 55, you lose!') if not input('Would you liek to play again?').lower() == 'y': break
main()
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Oct 6, 2017 08:06 AM)vorticalbox Wrote: I would keep functions to a Single responsibility as per https://en.wikipedia.org/wiki/Single_res..._principle
PHP Code
<?php from random import randint
def roll(): roll = randint(1,100) print('You rolled ', roll) return roll def check(n): if n > 55: return True else: return False
def main(): while True: if check(roll()): print('You rolled over 55 you win!') else: print('Sorry, you rolled under 55, you lose!') if not input('Would you liek to play again?').lower() == 'y': break
main()
true i always try to keep it simple. it may seem easier to have one function to do everything however one function should have one task
Knowledge is Power - Be Powerful!!!!!
LIFE IS A CHALLENGE SO ACCEPT IT!
(Oct 6, 2017 08:51 AM)koolkid Wrote: true i always try to keep it simple. it may seem easier to have one function to do everything however one function should have one task
Also spelling in prints is a good idea too -.-
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Oct 6, 2017 09:18 AM)vorticalbox Wrote: Also spelling in prints is a good idea too -.-
O.o
Knowledge is Power - Be Powerful!!!!!
LIFE IS A CHALLENGE SO ACCEPT IT!
hi, ("y" or "yes") isn't going to do the thing, it would have to be either:
Code reroll = "y" in input().lower() or "yes" in input().lower()
or what I'd prefer:
Code reroll = input().lower() in ["y", "yes"]
(Oct 6, 2017 10:03 AM)koolkid Wrote: O.o
I spelt like wrong in my code lol.
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Oct 6, 2017 10:37 AM)vorticalbox Wrote: I spelt like wrong in my code lol.
lol shit happens .. i need to code something
Knowledge is Power - Be Powerful!!!!!
LIFE IS A CHALLENGE SO ACCEPT IT!
(Oct 6, 2017 10:53 AM)koolkid Wrote: lol shit happens .. i need to code something
A bot the finds all the wrong spellings on threads and posts
*correct spelling
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Oct 6, 2017 10:56 AM)vorticalbox Wrote: A bot the finds all the wrong spellings on threads and posts
*correct spelling
😠 cant bother too tired.. monday to friday work days 😭 saturday is a busy day sunday is rest day .. sigh
Knowledge is Power - Be Powerful!!!!!
LIFE IS A CHALLENGE SO ACCEPT IT!
|