Question

How do you write a while loop that ends after the exact same word has been...

How do you write a while loop that ends after the exact same word has been entered twice by the user?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: Since the language is not specified I have done it in the Python. The logic remains constant and the reading of input changes, Storing the data in the type of data type differs like an array in Java, C, C++. Please check the logic

EXPLANATION: Explanation in the comments

SOLUTION:

word=[]
##list to store input words

loopBreak=0
##variable to store the loop break condition

while(loopBreak==0):
##read input word
string=input("Enter Word")

for i in range(len(word)):
##check if the enter word is in the list or not if it there in the list break the loop
##by changing the counter and break the current loop
if(word[i]==string):
print("You have entered a duplicate word")
loopBreak=1
break
##add the entered word to the list for comparison
word.append(string)

SOURCE CODE IMAGE:

File Edit Format Run Options Window Help word=[] ##list to store input words loopBreak=0 ##variable to store the loop break c

OUTPUT:

RESTART: C:/Users/vinod/AppData/local/Programs/Python/Python37-32/duplicateword .py Enter Wordhii Enter Wordhii You have ente

Add a comment
Know the answer?
Add Answer to:
How do you write a while loop that ends after the exact same word has been...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that uses a do or a while loop that has the user...

    Write a C++ program that uses a do or a while loop that has the user enter golf scores, terminated by a zero. After the zero has been entered, display the number of scores entered and their average.

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • USE of C++ please Write a program that achieves the following requirements: 1. A while/do-While loop...

    USE of C++ please Write a program that achieves the following requirements: 1. A while/do-While loop that will ask the user to input an integer on each iteration. The loop keeps a running total of the input and exits only when the total exceeds the first input times 10. 2. A for loop that does the exact same thing. The program should print out the *new* total each time the total is input.

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • Write a C++ program. Using the while loop or the do – while loop write a...

    Write a C++ program. Using the while loop or the do – while loop write a program that does the following: Calculate the average of a series of homework grades (0 - 100) entered one at a time. In this case the lowest score will be dropped and the average computed with the remaining grades. For example suppose you enter the following grades: 78, 85, 81, 90, 88, 93 and 97.The average will be computed from the 6 grades 85,...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • Write a while loop in java that will let the user enter a series of integer...

    Write a while loop in java that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates.

  • A simple game of chance Using a while loop write a simple coin flip game. Specifics:...

    A simple game of chance Using a while loop write a simple coin flip game. Specifics: The user starts with a bank of $10.00 It costs a dollar to play A correct guess pays $2.00 The while loop is used for the game loop. It should ask if the user wants to play. The while loop will check for a value of 'Y' or 'N'. You should also allow for lower case letters to be input. You MUST prime the...

  • (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers...

    (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers entered by the user:  Ask the user to enter an integer number or -1 to stop  Add the entered numbers  Compute the average of the numbers outside the loop after termination  Print the average

  • 2. Write a program that takes a word that a user enters into a textbox, and...

    2. Write a program that takes a word that a user enters into a textbox, and displays the word reversed in an output text box. If the word is a palindrome (if the reversed word is the same as the initial word like mom, dad, anna), have a message box appear saying the word entered is a palindrome. You may use either a pretest or posttest do loop. Change werd ChangeWord Word apple Word: hannah Flp Word Backwards Result elppa...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT