[Tutor] recursive function password check
Hi everyone, trying to write a program that has the user enter a password, checks if it contains any vowels, and if it does prints ' It is false that password(whatever the user enters) has no vowels,' and if it has no vowels prints it is True that password has no vowels... Here is what I have so far...def password(y): vowels=["a","e","i","o"] if y[0] in vowels: return False if len(y) ==0: return True elif(y[len(y)-1] != vowels): return False else: return password(y[1:len(y)-1])x=input("Enter a password:")print("It is", password(x),"that",x,"has no vowles") As of now it just asks for the password, and then prints 'It is False that password(whatever was entered) has no vowles' for any word I enter. I think maybe some of my if statement conditions may be being returned to the function, but then not printing the appropriate one? Can anyone help? Thanks!___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] distance between cities matrix
Hi everyone, Here is the question I was given...Consider the (20x20) array of numbers here(I wrote all of the numbers in my program). Lets say this represents a matrix A of distances (in kilometers) between cities. Note that A is symmetric A(i,j) = A(j,i) and all its diagonal elements are zero. Suppose Vladimir from city i and Petra from city j want to meet up in some third city k (i, j and k are all different). Conscious about their carbon footprint (!), they want k to be as near as possible: specifically the sum of the distances both has to travel should be minimum. Given i and j, write a program in PYTHON that determines what k should be. (In PYTHON you can store the matrix as a list of lists). Do not worry in your program about "reading in" A: Just hard-wire it in to the code. You should read in from the user the two cities (i and j) where Vladimir and Petra live. From your program, calculate the answer for1) i=5, j=112)i=10, j=13 I think my program is correct, but I'm not sure what they want us to do with the two conditions given above. I also don't know what to enter when I run the program to test these. I am working in Python 3. Thank you! 20x20matrix Description: Binary data ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor