jeudi 4 février 2016

How to get a program to repeat itself using a while loop and if statement? Python

I'm really new to Python and I'm finding it really hard to understand certain aspects of the language. I've been asked to create a program for an assignment and after hours of trying to use this website, I've come to no avail.

The question is: Write a program which uses a loop to take in the first name, last name and telephone number from an undefined number of users. The program should allow the user the option to quit, after each iteration of the loop. The program should also write the information entered by the user to a text file called names.tx

I have no problem with the part of the question in bold but I really can't wrap my head around the first bit. Here's what I have so far:

def main():

infoList = []
count = 0

while True:

firstname = input('Please enter your first name: ')
lastname = input('Please enter your last name: ')
telephoneno = input('Please enter your telephone number: ')
contiinue = input('Continue (y = yes): ')
if contiinue == y:
    count = count + 1

main()

When the program is iterating itself again, I want the user to be able to give different details to the questions. I know people hate when people ask questions and it seems like they're just trying to get people to do homework for them, but this will genuinely bug me for a while if I amn't able to find a resolution.

Aucun commentaire:

Enregistrer un commentaire