Python Forum

Full Version: Need help with something so simple
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys I am new to coding and just needed help with this program and the answer is probably quite obvious anyway this code wont print the pin and i am not sure how to fix it

password = input(" enter the 4 pin code")
guess = 1
while guess != password:
    print (guess)
    guess = guess + 1
if guess == password:
    print(guess)
Hello, please put your code in Python code tags. You can find help here.

Can you be a little more specific? By pin do you mean password variable? There is no print() for the password.
input will return str, so password is str, while guess is int
you need to convert password to int to be able to compare
Sorry, Yes i haven't been clear enough i meant the password variable when i said pin anyway the entire point is the person enters a number and the variable guess goes up by one until it reaches the value of the password then it stops and prints the password


[*]password = int(input("enter the 4 pin code: ")
guess = 1
while guess != password:
print (guess)
guess = guess + 1
if guess == password:
print(guess)

This didn't seem to work either sorry for being a derp

import os

password = int(input("enter the 4 pin code: ")
guess = 1
while guess != password:
print (guess)
guess = guess + 1
if guess == password:
print(guess)
then says invalid syntax and highlights the guess word on second line

Dont worry i fixed it sorry for wasting time
I am glad you solved it, feel free to post your solution.