I assume this is excel.
It will round so you'll see 234.6
Answer:
public class Pyramid {
public static void main(String[] args) {
int h = 7;
System.out.println("Pattern A");
for(int i = 1; i <= h; ++i)
{
for(int j = 1; j <= i; ++j) {
System.out.print("+");
}
System.out.println();
}
System.out.println();
System.out.println("Pattern B");
for (int i = 1; i<=h; ++i)
{
for(int j = h; j >=i; --j){
System.out.print("+");
}
System.out.println();
}
}
}
Explanation:
- The trick in this code is using a nested for loop
- The outer for loop runs from i = 0 to the heigth of the triangle (in this case 7)
- The inner for loop which prints the (+) sign runs from j = 0 to j<=i
- It prints the + using the print() function and not println()
- In the pattern B the loop is reversed to start from i = height
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("%s Seconds\n" % bag_ounces)
Explanation:
- Using Python Programming Language
- The function is defined to accept an int parameter
- Within the function body, if...elif and else statements are used to print the desired output
- note the use of the %s placeholder (formated output) and \n for a new line in the final print statement