93.9k views
1 vote
ad 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. Complete the program to read the needed values from input, that the existing output statement(s) can use to output a short story. Ex: If the input is:

1 Answer

5 votes

Answer:

Python

name =input("") #input name

location = input("") #input location

number = int(input("")) #input number

pluralNoun = input("") #input plural noun

print(name, 'went to', location, 'to buy', number, 'different types of', pluralNoun) #prints the short story using input variables

JAVA:

import java.util.Scanner; // to accept input from user

public class Main {

public static void main(String[] args) { //start of main function

Scanner input = new Scanner (System.in) ; //creates Scanner class object

String subject; //declares string type variable to hold name

String location; //declares string type variable to hold location

int number; //declares int type variable to hold number

String object; //declares string type variable to hold plural noun

subject = input.next(); //reads input subject string value

location = input.next(); //reads input location string value

number = input.nextInt(); //reads input number integer value

object = input.next(); //reads input object string value

System.out.println(subject + " went to " + location + " to buy " + number + " different types of " + object + "."); } } //prints the short story using input values and existing string added with input values

In C++

#include <iostream> //to use input output functions

using namespace std; //to identify objects like cin cout

int main(){ //start of main function

string first_name; // string variable that holds the first_name value

cin>>first_name; //reads the first_name from user

string generic_location; // string variable that holds the generic location

cin>>generic_location; //reads the generic location from user

int whole_number; // int variable that holds the whole_number value

cin>>whole_number; //reads the whole number from user

string plural_noun; // string variable that holds the plural_noun value

cin>>plural_noun; //reads the plural_noun from user

cout<<first_name<<" went to "<< generic_location<<" to buy "<< whole_number<<" different types of "<<plural_noun;} //prints the short story using input values and existing string added with input values

Explanation:

The complete statement is:

If the input is:

Ex: If the input is

Eric

Chipotle

12

cars

Then the output is:

Eric went to Chipotle to buy 12 different types of cars

Now to complete this program we read the needed values from input, that the existing output statements can use to output a short story.

If you look at the input Eric which is a name can be used as an input value as the name can be different for different users. Chipotle is a location that should aslo be an input value because locations can vary too of different users. 12 is a numeric that can also vary. For example a person can have more than or less than 12 cars. Lastly, cars which is plural noun can also be used as input value. Now to get the above output we concatenated the input variables with the strings in the print statement in order to output a short story.

You can name the variables whatever you like as i have used different variable names in different programs.

ad Libs are activities that have a person provide various words, which are then used-example-1
ad Libs are activities that have a person provide various words, which are then used-example-2
ad Libs are activities that have a person provide various words, which are then used-example-3
User Spencergibb
by
5.0k points