145k views
1 vote
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. Sample output with input: 7 42 seconds

User Mcabral
by
4.8k points

2 Answers

2 votes

Answer:

def print_popcorn_time(bag_ounce):

if bag_ounce<3:

print("Too small")

elif bag_ounce > 10:

print ("Too large")

else:

print(6*bag_ounce, "seconds")

Step-by-step explanation:

User Plugwash
by
5.4k points
4 votes

Answer:

public static void print_popcorn_time(int bag_ounces){

if(bag_ounces<3){

System.out.println("Too Small");

}

else if(bag_ounces>10){

System.out.println("Too Large");

}

else{

bag_ounces*=6;

System.out.println(bag_ounces+" seconds");

}

}

Step-by-step explanation:

Using Java prograamming Language.

The Method (function) print_popcorn_time is defined to accept a single parameter of type int

Using if...else if ....else statements it prints the expected output given in the question

A complete java program calling the method is given below

public class num6 {

public static void main(String[] args) {

int bagOunces = 7;

print_popcorn_time(bagOunces);

}

public static void print_popcorn_time(int bag_ounces){

if(bag_ounces<3){

System.out.println("Too Small");

}

else if(bag_ounces>10){

System.out.println("Too Large");

}

else{

bag_ounces*=6;

System.out.println(bag_ounces+" seconds");

}

}

}

User TizzyFoe
by
5.7k points