float
or enclosing it in double quotes if it’s a str
.
9 / 3
9 // 3
10 // 3
10 % 3
3 % 10
2 ** 3
"abc" + "def"
"baa " * 2
(9 % ( 6 // 2))
9 % 6 // 2
2 ** 2 ** 4
("na" * 8 + " ") * 2 + "Batman!"
1 + 2 ** 3 / 4 * 5 - (6 % 7)
For each of the following, say whether it is a statement or an expression:
a = 4
a + 4
int(6.4) + 2
Suppose we run the following program, and the user types 6
and presses enter. What happens?
Suppose we run the following program, and the user types 6
and presses enter. What value gets stored in result
?
What does the following expression evaluate to? float(str(int(2.6 / 2))*2)
Enter the first number: 4
Enter the second number: 2.4
Enter the third number: 8.6
Your numbers total 15.0
Write a program to help a user calculate percentages. First prompt the user for an amount, then prompt the user for a percentage. Finally, print the percentage of the amount. The amounts and percents should handle floating-point values, but your program may throw an error if the user enters something that’s not a number. A sample run of the program might look like this:
Enter an amount: 900
Enter a percentage: 50.0
50.0 percent of 900 is 450.0
Modify your program from #1 to print the full equation for the sum; for example, the last line of the example above would read
4.0+2.4+8.6=15.0
The catch: you have to print the equation without spaces between the numbers.