can someone explain how to do this in python? the idea is to figure out the 4 digit code(ex: 3968) entered by the user. how would one design an algorithm to go about finding this?
here is what i got..:
code=int(input("Enter 4 digit secret code:"))
count=0000
while(count!=code):
count=count+1
print("Your code was",count)
this works perfectly….Except when the code starts with 0… Ex: 0387
it prints ” Your code was 387″ as appose to 0387
whats a quick fix for this?
The % means that here comes a variable.
The 04 means zero-pad it to four characters.
The i means it’s an integer. Docs here.
Alternative version, using the new, more flexible
.format()formatting: