We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bd06bff commit 035756fCopy full SHA for 035756f
ch08-conditional-logic/6-recover-from-errors.py
@@ -2,13 +2,27 @@
2
# Solution to review exercises
3
4
5
+# Exercise 1
6
# Ask the user to enter an integer.
7
# Repeat the process if the user hasn't entered an integer.
-repeat = True
8
-while repeat:
+while True:
9
try:
10
my_input = input("Type an integer: ")
11
print(int(my_input))
12
- repeat = False
+ break
13
except ValueError:
14
print("try again")
15
+
16
17
+# Exercise 2
18
+# Print character and specifid index in string
19
20
+input_string = input("Enter a string: ")
21
22
+try:
23
+ index = int(input("Enter an integer: "))
24
+ print(input_string[index])
25
+except ValueError:
26
+ print("Invalid number")
27
+except IndexError:
28
+ print("Index is out of bounds")
0 commit comments