Professional Documents
Culture Documents
Practice 2
Practice 2
old = 16
grade = 9.2
print("It's %s, %d. Level: %f" % (pupil, old, grade))
Results:
It's Ben, 16. Level: 9.200000
Questions:
what do you think %s, %d,%f means?
Task 3
Ask the user for four numbers. Fold the first two separately
and the second two separately. Divide the first amount by
the second. Display the result on the screen so that
the answer contains two digits after the decimal point.
Operator IF ELSE
If boolean_expression
{expression 1; expression 2; … } a=5>0
else
{expression 3;
if a:
… print(a)
}
Operator try-except
You can describe its work in words like this: “Try to do this and that, if an exception occurs,
then do this and that.” Its construction is similar to a conditional statement with an
else branch.
n = input(“Input number: ")
try:
n = int(n)
print(“GOOD")
except:
print(" Something went wrong ")
TASK1
Write a program that prompts you for two values. If at least one of them is not a number,
then concatenation, that is, joining, of strings must be performed. In other cases,
the entered numbers are summed.
Example
First value: 4 First value: a
Second value: 5 Second value: 9
Result: 9.0 Result: a9