0

I want to write the elif loop to catch the user if they try to enter a wrong answer to passcode.

The count reinitializes to zero at the beginning of the loop. I want the count to count up from zero and retain its value throughout the whole process.

while(1):
    print("Welcome to my Computer Science Homwework")
    passWord = input("Please tell me the Password")
    tempList = []
    count=0
    if passWord=='Password':
        print("Welcome to my Computer Science Program")
        Pin,lastname = input("Enter Your Pin, then your last name with a 
space between").split()
        tempList.append(Pin)
        tempList.append(lastname)
        if (len(tempList) == 2):
            if (float(tempList[0]) == 1234):
                print("Correct Code")
                str = input("Please enter 10 times 10")
                if (int(str, 2) == 4):
                    if ((int(str) % 10) == 0):
                        print("That is correct")
        sevenDayWeek = ["Day 1","Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7"]
        for x in range(7):
            salary = input('What was your hourly salary for ' + sevenDayWeek[x] + '(in US Dollars)?')
            hours = input("How many hours did you work?")
            overtime = input("How many overtime hours did you work? (overtime pays 1.5 times your salary)")
            salaryDeduction = input("Please enter the total dollar value of your salary deduction for " + sevenDayWeek[x] + "?")
            dailySalary = float(salary) * float(hours) + float(overtime) * float(salary) * 1.5 - float(salaryDeduction)
            print('Your salary for ' + sevenDayWeek[x] + ' is')
            print("$",dailySalary)
            totalSalary=+dailySalary
           print("Your total salary for the week so far is:", totalSalary)
        else:
            break
    elif(count <1):
        count+= 1
    else: break
  • 2
    Follow your logic through. Why does it re-initialize? What could you do instead to prevent it? – Cfreak Sep 08 '19 at 14:30
  • it re-initializes at line 5. I would prevent this re-initialization by putting count somewhere lower?? – Jordan Greenhut Sep 08 '19 at 14:32
  • what is this code supposed to do? what are the input and the expected output? –  Sep 08 '19 at 14:35
  • I want the user to only be able to enter two wrong passwords. After the user enters two wrong passwords, the program breaks. – Jordan Greenhut Sep 08 '19 at 14:36
  • 1
    Put the `count = 0` line outside of your `while` so it doesn't reset the value to zero after subsequent iterations. – Mihai Chelaru Sep 08 '19 at 15:26
  • Possible duplicate of [Add a counter to while loop python](https://stackoverflow.com/questions/42040868/add-a-counter-to-while-loop-python) – Mihai Chelaru Sep 08 '19 at 15:31

0 Answers0