The output will be: You owe $ 15.0
Here is an HTML example with the CSS class defined inline:
<!doctype html>
<html>
<head>
<style>
.YellowBackground {
background-color : yellow;
}
</style>
</head>
<body class="YellowBackground">
<h1>A yellow background</h1>
</body>
</html>
Answer:
The program in Python is as follows:
num1 = int(input())
num2 = int(input())
if num1 >=0 and num2 >= 0:
print(num1+num2)
elif num1 <0 and num2 < 0:
print(num1*num2)
else:
if num1>=0:
print(num1**2)
else:
print(num2**2)
Explanation:
This gets input for both numbers
num1 = int(input())
num2 = int(input())
If both are positive, the sum is calculated and printed
<em>if num1 >=0 and num2 >= 0:</em>
<em> print(num1+num2)</em>
If both are negative, the products is calculated and printed
<em>elif num1 <0 and num2 < 0:</em>
<em> print(num1*num2)</em>
If only one of them is positive
else:
Calculate and print the square of num1 if positive
<em> if num1>=0:</em>
<em> print(num1**2)</em>
Calculate and print the square of num2 if positive
<em> else:</em>
<em> print(num2**2)</em>
Answer:
A function with out parameters cannot take any arguments or perform operations on variables passed in. A function with parameters can.
To accomplish this without using a loop,
we can use math on a string.
Example:
print("apple" * 8)
Output:
appleappleappleappleappleappleappleapple
In this example,
the multiplication by 8 actually creates 8 copies of the string.
So that's the type of logic we want to apply to our problem.
<span>def powersOfTwo(number):
if number >= 0:
return print("*" * 2**number)
else:
<span>return
Hmm I can't make indentations in this box,
so it's doesn't format correctly.
Hopefully you get the idea though.
We're taking the string containing an asterisk and copying it 2^(number) times.
Beyond that you will need to call the function below.
Test it with some different values.
powersOfTwo(4) should print 2^4 asterisks: ****************</span></span>