do all the problems using while loop continue and break 1Th

do all the problems using while loop , continue and break

1-This problem provides practice using a while True loop.write a function named twoWords that gets and returns two words from a user. The first word is of a

specified length, and the second word begins with a specified letter.The function twoWords takes two parameters:

an integer, length, that is the length of the first word and

a character, firstLetter, that is the first letter of the second word. The second word may begin with either an upper or lower case instance of firstLetter.The function twoWords should return the two words in a list.Use a while True loop and a break statement in the implementation of twoWords.

2-Write a function named twoWordsV2 that has the same specification as Problem 1, but implement it

using while and not using break. (Hint: provide a different boolean condition for while.)

Since only the implementation has changed, and not the specification, for a given input the output

should be identical to the output of problem 1

3-Write a function geometric ()that takes a list of integers as inputs and returns true if the integers in the list form a geometric sequence.(hint a sequence is geomtric if the ratio of a0/a1, a2/a1,a3/a2 are all equal)

4-implemet a function mystery() that takes as input a positive integer n and answer this question, how many times can n be halved(using integer division) before reaching 1?

5- Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the entered password has 8-15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests.

Solution

1.def twoWords(length,firstLetter):

firstWord = \"\"

secondWord= \"\"

while True:

firstWord = input(\'A \' + str(length) + \'-letter word please.\')

if length == len(firstWord):

break

while True:

secondWord = input(\'A word beginning with \' + firstLetter+ \' please\')

if secondWord[0] == firstLetter.upper() or secondWord[0] == firstLetter.lower():

break

return [firstWord,secondWord]

print(twoWords(4,\'B\'))

5.

def enterNewPassword():

password = input(\"Enter a password: \")

if len(password) < 8:

print(\"Your password does not contain 8-15 characters.\")

if len(password) > 15:

print(\"Your password contains more than 15 characters.\")

if ??? not in password:

print(\"Your password does not contain a digit.\")

if ??? in password and 8 <= len(password) >= 15:

print(\"Good password!\")

enterNewPassword()

do all the problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and
do all the problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site