Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Intermediate Git 2020
Demo 2
Commits
4e24f594
Commit
4e24f594
authored
Nov 01, 2020
by
Gilles Coremans
Browse files
Retry inputs when given bad input
parent
02baeedf
Changes
1
Hide whitespace changes
Inline
Side-by-side
calc.py
View file @
4e24f594
parsed
=
False
operand1
=
input
(
"First operand: "
)
operator
=
input
(
"Operator: "
)
operand2
=
input
(
"Second operand: "
)
while
not
parsed
:
try
:
operand1
=
int
(
operand1
)
parsed
=
True
except
ValueError
:
print
(
operand1
+
" is not a number!"
)
operand1
=
input
(
"First operand: "
)
try
:
operand1
=
int
(
operand1
)
except
ValueError
:
print
(
operand1
+
" is not a number!"
)
exit
(
1
)
operator
=
input
(
"Operator: "
)
try
:
operand2
=
int
(
operand2
)
except
ValueError
:
print
(
operand2
+
" is not a number!"
)
exit
(
1
)
operand2
=
input
(
"Second operand: "
)
while
not
parsed
:
try
:
operand2
=
int
(
operand2
)
parsed
=
True
except
ValueError
:
print
(
operand2
+
" is not a number!"
)
operand2
=
input
(
"Second operand: "
)
print
(
"Your result is:"
)
if
operator
==
"+"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment