Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First program feedback
#1
Hi,

I am new to python and i have been using it for 2 days now and have so far learnt statements and loops e.g. the while/for loops and elif statements etc. I have created a program based on a practice exercise question i found on the internet and have created my first program. Its a pointless program which just asks a user for a password and to keep asking a few times if entered wrong and grant access if correct. (Took me about an hour to write this hahhahaha but proud of myself). Anyway, i was wondering if anyone could have a look at it and see if theres any bad habits ive picked up or anyway i coulf iron the code out to make it look neater or just general feedback. Any advice would be appreciated. I have included it below.

print ('Please enter password')
password = input ()
n = 4
while password != 'swordfish':
    while n > 1:
        print ('Incorrect password. Try again. The number of attempts remaining is ' + str(n-1))
        n = n - 1
        password = input()
        while n == 1:
            print ('Access Blocked')
            break
if password == 'swordfish':
    print ('Access granted')
Edit: indentations are not showing on this post. here is a screenshot of it https://ibb.co/n7XuHn
Larz60+ wrote Mar-12-2018, 11:08 AM:
Edit: indentations are not showing on this post. here is a screenshot of it https://ibb.co/n7XuHn
You need to use BBCODE tags please read: https://python-forum.io/misc.php?action=help&hid=25
I added for you this post
Quote
#2
Ok. Its been some time since you've posted this but still here is your feedback.
Here is the output I got for entering a wrong password (is it meant to do that?)
Please enter password
hello
Incorrect password. Try again. The number of attempts remaining is 3
swordfish
Incorrect password. Try again. The number of attempts remaining is 2
swordfish
Incorrect password. Try again. The number of attempts remaining is 1
swordfish
Access Blocked
Access granted
>>> 
Also, you can do this instead. for line 1 and 6
>>> input('Enter something: ')
Is pretty much the same as

>>> print('Enter something: ')
>>> input()
The while loop in line 9 is not required. You could just use an if statement like this

if n == 1:
    print('Access Blocked')
Other than that I don't see anything that looks off.
Now one thing I will say is that in the second while loop at line 5, it seems to me that you need to check the password to see if it's entered correctly but that's just me the question could have been different.

Keep it up :)
Quote
#3
(Mar-21-2018, 09:59 AM)tannishpage Wrote: Ok. Its been some time since you've posted this but still here is your feedback. Here is the output I got for entering a wrong password (is it meant to do that?)
 Please enter password hello Incorrect password. Try again. The number of attempts remaining is 3 swordfish Incorrect password. Try again. The number of attempts remaining is 2 swordfish Incorrect password. Try again. The number of attempts remaining is 1 swordfish Access Blocked Access granted >>> 
Also, you can do this instead. for line 1 and 6
 >>> input('Enter something: ') 
Is pretty much the same as
 >>> print('Enter something: ') >>> input() 
The while loop in line 9 is not required. You could just use an if statement like this
 if n == 1: print('Access Blocked') 
Other than that I don't see anything that looks off. Now one thing I will say is that in the second while loop at line 5, it seems to me that you need to check the password to see if it's entered correctly but that's just me the question could have been different. Keep it up :)

Sorry about the late response. I haven't been on here in a while after a had troule logging back in. But I have now taken on your advice and it seems better structured now though. Thanks. Still got a long way to go though to progress
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Hangman game, feedback appreciated WolfWayfarer 8 92 Yesterday, 01:26 PM
Last Post: ichabod801
  Feedback on my first program? jibby 6 304 Jul-16-2018, 08:42 AM
Last Post: WolfWayfarer
  Feedback on first Class fffrost 2 129 Jul-01-2018, 05:54 PM
Last Post: fffrost
  My First Python Script. Feedback Sought. malonn 5 196 Jun-29-2018, 03:49 PM
Last Post: Zombie_Programming
  Feedback on my first Python module CodeRaker 11 304 Jun-21-2018, 02:16 AM
Last Post: ichabod801
  Feedback on a test adventure? Panda 2 106 Jun-15-2018, 06:18 PM
Last Post: nilamo
  Looking for feedback for pyPhpTree Alextp 0 118 May-16-2018, 12:03 PM
Last Post: Alextp
  Looking for feedback on a game I made MrPucake 7 432 Apr-04-2018, 01:53 PM
Last Post: MIPython
  I need some feedback on this program tannishpage 3 372 Mar-22-2018, 05:31 AM
Last Post: tannishpage
  Feedback on module GamePatrol 1 207 Mar-06-2018, 07:40 AM
Last Post: Gribouillis

Forum Jump:


Users browsing this thread: 1 Guest(s)