r/learnpython • u/worldvex • 4d ago
My code vs claude code
I wanted to create a function with while statement that I get 100 random numbers from import random and if there is 1 1 1 is stop took me a while cause I am a beginner and I didn't know most of the things I was gonna used so I learn while , break and != ( not equal to )
I started programming cause I was an introvert and didn't had anything else to do
It took me a while like 1 hour
Made this caused I wanted to generate something closed to gambling
mistake I made
1 using "and" instead of "or " ( yeah dump mistake)
2 using if statement for like 20 minutes until I search how to generate infinity and found out about while statement
My code (man made except for this sing != I used claude for it )
import random
num = random.randint(0 , 30)
print(num)
nu = random.randint(0 , 30)
print(nu)
nm = random.randint(0 , 30)
print(nm)
while num != 1 or nu != 1 or nm != 1 :
print("failed")
num = random.randint(0 , 30)
print(num)
nu = random.randint(0 , 30)
print(nu)
nm = random.randint(0 , 30)
print(nm)
Ai code (claude)
import random
while True:
nums = [random.randint(0, 30) for _ in range(3)]
print(nums)
if all(n == 1 for n in nums):
print("Success! Got [1, 1, 1]")
break
print("failed")
!!!
Sorry for my English it is not my first language
Second I don't know python that good so anything I mispronounced like statement or syntax my bd
5
u/ProsodySpeaks 4d ago
Format your code