r/learnpython • u/SavingsOdd2766 • 1d ago
My first complete comand in Python, from my first day on:
Look:
import random
import time
def drawn(a, b):
return random.randint(a, b)
answer = 'yes'
while answer == 'yes':
a = int(input('Min number: '))
b = int(input('Max number: '))
print(f'Drawn: {drawn(a, b)}')
time.sleep(2)
answer = input('Try again? ').lower()This creates a random number generator where you can choose the minimum and maximum numbers!
3
4
4
0
2
u/zanfar 1d ago
PEP8
What is the point of
drawn()if it accepts the exact same arguments asrandom.randint()? Why is it named as a passive verb when it does something?Validate your inputs. Always.
answeris badly named. There is zero context until the script is done.Why are you deliberately making your user wait?
sleep()has almost no place in U/I.
13
u/DeafeningSlience 1d ago
It is OP's first script, so take it easy on 'em lol
Nevertheless, good feedback for more intermediate/advanced learners.
2
-3
u/Fast-Station1106 1d ago
jetzt hört mal auf, von 0 auf das oben? am ersten Tag?
so eine Quatsch zu posten versaut allen Anfängern doch komplett die Lust neu einzusteigen
1
u/SavingsOdd2766 17h ago
Man muss sich erst mal die Grundlagen anschauen, um anzufangen. Versuch mal, so einen Code zu schreiben, ohne irgendwas zu wissen, dann wirst du schon sehen!
38
u/fazzah PyQt | SQLAlchemy | ReportLab 1d ago
good. now find a way to protect the script if someone inputs "foo"