Answer to Question #289686 in Python for John

Question #289686

Friends

by Rhea Tortor

You task is to write a program that will continuously add friend data to a list named friends until the user enters "No". The program must display the contents of friend list.


friend's data to be collected:

Last name

First name

Birthdate

Gender

Contact No.



Validation:

Name must not be empty.

Must check the validity of the birth date.

Gender either F or M only.

Contact No. must be exactly 11 digits.


Display "Invalid input!" and ask the user to input another value.

Input

Friend's data

Tortor
Rhea
12/25/1990
F
09172345678
No

Output


Name:·Rhea·Tortor
Birthdate:·December·25,·1990
Gender:·Female
Contact·No.:·09172345678
1
Expert's answer
2022-01-22T16:35:18-0500
# Python program to check for the sum
# condition to be satisified


def hasArrayTwoCandidates(A, arr_size, sum):
	
	# sort the array
	quickSort(A, 0, arr_size-1)
	l = 0
	r = arr_size-1
	
	# traverse the array for the two elements
	while l<r:
		if (A[l] + A[r] == sum):
			return 1
		elif (A[l] + A[r] < sum):
			l += 1
		else:
			r -= 1
	return 0


# Implementation of Quick Sort
# A[] --> Array to be sorted
# si --> Starting index
# ei --> Ending index
def quickSort(A, si, ei):
	if si < ei:
		pi = partition(A, si, ei)
		quickSort(A, si, pi-1)
		quickSort(A, pi + 1, ei)


# Utility function for partitioning
# the array(used in quick sort)
def partition(A, si, ei):
	x = A[ei]
	i = (si-1)
	for j in range(si, ei):
		if A[j] <= x:
			i += 1
			
			# This operation is used to swap
			# two variables is python
			A[i], A[j] = A[j], A[i]


		A[i + 1], A[ei] = A[ei], A[i + 1]
		
	return i + 1
	


# Driver program to test the functions
A = [1, 4, 45, 6, 10, -8]
n = 16
if (hasArrayTwoCandidates(A, len(A), n)):
	print("Array has two elements with the given sum")
else:
	print("Array doesn't have two elements
								with the given sum")


## This code is contributed by __Devesh Agrawal__

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS