209k views
5 votes
Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bag_ounces followed by "seconds". End with a newline.

User Georgette
by
5.5k points

2 Answers

1 vote

Answer:

def print_popcorn_time(bag_ounces):

if bag_ounces < 3:

print("Too small")

elif bag_ounces > 10:

print("Too large")

else:

bag_ounces = bag_ounces * 6

print(bag_ounces, "seconds")

Step-by-step explanation:

def print_popcorn_time(bag_ounces): #fed function

if bag_ounces < 3: #1st if statement

print("Too small") #print function

elif bag_ounces > 10: #else if

print("Too large") #print than print

else: #else:

bag_ounces = bag_ounces * 6 #do work

print(bag_ounces, "seconds") #print

User Smagnan
by
5.1k points
1 vote

Answer:

void print_popcorn_time(int bag_ounces){

if(bag_ounces < 3){

cout<<"Too small"<<endl;

}else if(bag_ounces > 10){

cout<<"Too large"<<endl;

}else{

cout<<(6 * bag_ounces)<<"seconds"<<endl;

}

}

Step-by-step explanation:

The function is the block of the statement which performs the special task.

For checking the condition in the program, the if-else statement is used.

It can check the condition one or two but if we want to check the more than two different conditions then the continuous if-else statement is used.

syntax of continuous if else:

if(condition){

statement;

}else if(condition)

statement;

}else{

statement;

}

In the question, there are three conditions;

1. bag_ounces is less than 3

2. bag_ounces greater than 10

3. else part.

we put the condition in the above if-else statement and print the corresponding message.

User Uri Shtand
by
4.9k points