-4,563,432,873,332 4.73-e39 "dog'
"This is line 1./n" false
Ans: 4,563,432,873,332 no commas allowed, it's okay to be
larger than 2 billion;
4-e39 should be 4e-39;
"dog' quotes must be balanced, should
be "dog" or 'dog';
'This is line 1./n' should be 'This is line 1.\n' for
the \n to acts as a new line character.
false should be False, Python is case sensitive.
value = 3.14159265Write a statement to round off value to four digits after the decimal point.
print(round(value, 4))
a = 3
b = 5
a = 2 * a + b
b = a + 3 * b
a = a // 2
b = b // 3
print("sum = ", a + b)
Ans:
Variable trace: Output:
a b sum = 13
----+----
3 | 5
11 | 26
5 | 8
| a - 2b / 7 | |
| s = | |
| c + (d - 5e)-x + 3y |
Ans: s = (a - 2 * b / 7) / (c + (d - 5 * e) ** (-x + 3 * y))
Define velocity of light as C = 2.998e8
Input rest mass
If rest mass < 0
Print error message
Exit script
End if
Input velocity
If velocity >= C
print error message
exit script
End if
Compute actual velocity from rest mass
and velocity using Einstein's formula.
Print actual velocity.
Ans:
import sys
C = 2.998e8
# Input and validate rest mass.
m0 = float(input("Enter rest mass" "))
if m0 < 0:
print("Rest mass must be nonnegative: ")
sys.exit( )
# Input and validate velocity.
if v >= C:
print("Velocity must be < C: ")
sys.exit( )
# Compute and print actual mass.
m = m0 / (1 - (v / C) ** 2) ** 0.5
print("Actual mass:", m)
# You can also write the formula for actual mass like this:
import math
m = m0 / math.sqrt(1 - (v / C) ** 2)
Initialize counter to 1.
while counter is less than or equal to 100
Print value of counter.
Add one to counter.
end
Input hours worked from keyboard.
Input hourly salary from keyboard.
if hours worked is greater than 40
Set wages to 40 * hourly salary
plus overtime hours * hourly salary * 1.5
else
Set wages to hours worked * hourly salary.
end
Output wages.