Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

do all the problems using while loop , continue and break( using python) 1-This

ID: 3797452 • Letter: D

Question

do all the problems using while loop , continue and break( using python)

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.

Explanation / Answer

Code:

#!/usr/bin/python3

def twoWords(n,c):

while True:
l2=input("Enter 1st string of %d characters:" %n);
if(len(l2)==n):
break;
while True:
l3=input("Enter 2nd string with starting char %c:" %c).lower();
if(l3[0]== c[0]):
break;
return (l2,l3);

def twoWordsV2(n,c):

flag=True;

while flag:
l2=input("Enter 1st string of %d characters:" %n);
if(len(l2)==n):
flag=False;

flag=True;
while flag:
l3=input("Enter 2nd string with starting char %c:" %c).lower();
if(l3[0]== c[0]):
flag=False;
return (l2,l3);

def geometry(ll):

n=len(ll)
gm=ll[1]//ll[0];
print("GM %d" %gm);
i=2;

while i<n:
print("GM on loop:%d %d" %(i, ll[i]//ll[i-1]));
if(ll[i]//ll[i-1] != gm):
print("Not a GM series");
return False;
i=i+1;
return True;

def mystery(n):
n=int(n);
count=0;

while(n>1):
n=n//2;
count=count+1;

return count;

if __name__=='__main__':
n=int(input("Enter number of characters for 1st word:"))
c=input("Enter first char to be read for 2nd word:").lower()
ll=twoWords(n,c);
print(ll);
ll=twoWordsV2(n,c);
print(ll);

if(geometry([2,4,8,16])):
print("The series is geometric");
else:
print("The series is not geometric");

num=int(input("Enter number:"))
count=mystery(num);
print("%d can be halved %d times" %(num,count));

Output:

Enter number of characters for 1st word:6
Enter first char to be read for 2nd word:f
Enter 1st string of 6 characters:madesh
Enter 2nd string with starting char f:fdisk
('madesh', 'fdisk')
Enter 1st string of 6 characters:madeshrr
Enter 1st string of 6 characters:rmades
Enter 2nd string with starting char f:Finger
('rmades', 'finger')
GM 2
GM on loop:2 2
GM on loop:3 2
The series is geometric
Enter number:10
10 can be halved 3 times