3.11 LAB: Mad Lib - loops
Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.
Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit 0.
Ex: If the input is:
apples 5 shoes 2 quit 0
the output is:
Eating 5 apples a day keeps the doctor away. Eating 2 shoes a day keeps the doctor away.
Note: This is a lab from a previous chapter that now requires the use of a loop.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */
}
}
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner in = new Scanner(System.in); String word; int count; while (true) { word = in.next(); count = in.nextInt(); if (word.equals("quit") && count == 0) break; System.out.println("Eating " + count + " " + word + " a day keeps the doctor away."); } } }
3.11 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various...
16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name:...
16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name: Eric Enter a place:...
You will create your own silly story based on information provided by the user. For example, the parts in bold were entered by the user. For ideas see: Mad Libs. My Silly Story name: Frank Zhang whole number: 345 body part: stomach noun: cup floating point number: 1.23 clothing article: hat destination: Colorado goal: degree The resulting story is: Congratulations! Today is your 345 day. You're off to Colorado! You're off and away! You have brains in your stomach, You...