Python Forum
Need help with something so simple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with something so simple
#1
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)
Reply
#2
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.
Reply
#3
input will return str, so password is str, while guess is int
you need to convert password to int to be able to compare
Reply
#4
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
Reply
#5
I am glad you solved it, feel free to post your solution.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020